Java Reference
In-Depth Information
@Override
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D)g;
float delta = 60; // Increment
between stars
float starty = 0; // Starting y
position
// Draw 3 rows of 4 stars
GeneralPath star = null;
for(int yCount = 0 ; yCount<3; yCount++) {
starty += delta; // Increment row
position
float startx = 0; // Start x
position in a row
// Draw a row of 4 stars
for(int xCount = 0 ; xCount<4; xCount++) {
star = Star.starAt(startx += delta, starty);
g2D.setPaint(Color.GREEN);
// Color for fill is
green
g2D.fill(star);
// Fill the star
g2D.setPaint(Color.BLUE);
// Drawing color blue
g2D.draw(star);
}
}
}
Directory "StarApplet 2 filled stars"
You also need an import statement for the GeneralPath class name in the StarApplet.java source
file:
import java.awt.geom.GeneralPath;
Now the applet window looks something like that shown in Figure 19-19 , but in color, of course.
FIGURE 19-19
 
 
Search WWH ::




Custom Search