What do you suppose happens if you forget the match to a
<head>
tag?
The rest of the file is regarded as part of the head, and will not show up in the browser as you exepct.
The previous applets in this chapter have only printed text. Here is an applet that draws a circle.
import java.applet.Applet; import java.awt.*; // assume that the drawing area is 150 by 150 public class JustOneCircle extends Applet { final int radius = 25; public void paint ( Graphics gr ) { setBackground( Color.lightGray ); gr.drawOval( (150/2 - radius), (150/2 - radius), radius*2, radius*2 ); } }
Here is what the applet paints with your Web browser:
The method
drawOval()
is one of the methods of a
Graphics
object.
It looks like this:
drawOval( int X, int Y, int width, int height )
This draws a circle or an oval that fits within the rectangle specified by the X, Y, width and height arguments. The oval is drawn inside a rectangle whose upper left hand corner is at (X, Y), and whose width and height are as specified.