Java Reference
In-Depth Information
// Class defining a pane on which to draw
class StarPane extends JComponent {
@Override
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D)g;
float delta = 60f;
// Increment between
stars
float starty = 0f;
// Starting y
position
// Draw 3 rows of stars
for(int yCount = 0; yCount < 3; yCount++) {
starty += delta;
// Increment row
position
float startx = 0f;
// Start x position
in a row
// Draw a row of 4 stars
for(int xCount = 0; xCount<4; xCount++) {
g2D.draw(Star.starAt(startx += delta, starty));
}
}
}
}
}
Directory "StarApplet 1"
The HTML file for this applet could contain:
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "StarApplet.class"
width = "360"
height = "240"
>
</applet>
</center>
</body>
</html>
This is large enough to accommodate our stars. If you compile and run the applet, you should see the
Applet Viewer window shown in Figure 19-18 .
FIGURE 19-18
 
 
Search WWH ::




Custom Search