Java Reference
In-Depth Information
6 /**
7 An applet that draws two rectangles.
8 */
9 public class RectangleApplet extends
JApplet
10 {
11 public void paint(Graphics g)
12 {
13 // Prepare for extended graphics
14 Graphics2D g2 = (Graphics2D) g;
15
16 // Construct a rectangle and draw it
17 Rectangle box = new
Rectangle( 5 , 10 , 20 , 30 );
18 g2.draw(box);
19
20 // Move rectangle 15 units to the right and 25
units down
21 box.translate( 15 , 25 );
22
23 // Draw moved rectangle
24 g2.draw(box);
25 }
26 }
63
64
To run this applet, you need an HTML file with an applet tag. HTML, the
hypertext markup language, is the language used to describe web pages. (See
Appendix H for more information on HTML.) Here is the simplest possible file to
display the rectangle applet:
To run an applet, you need an HTML file with the applet tag.
ch02/applet/RectangleApplet.html
1 <applet code=ÐRectangleApplet.classÑ
width=Ð300Ñ height=Ð400Ñ>
2 </applet>
If you know HTML, you can proudly explain your creation, by adding text and
more HTML tags:
Search WWH ::




Custom Search