Java Reference
In-Depth Information
Point2D.Float point = new Point2D.Float(x, y);
p = new GeneralPath(GeneralPath.WIND_NON_ZERO);
p.moveTo(point.x, point.y);
p.lineTo(point.x + 20.0f, point.y - 5.0f);
// Line from
start to A
point = (Point2D.Float)p.getCurrentPoint();
p.lineTo(point.x + 5.0f, point.y - 20.0f);
// Line from
A to B
point = (Point2D.Float)p.getCurrentPoint();
p.lineTo(point.x + 5.0f, point.y + 20.0f);
// Line from
B to C
point = (Point2D.Float)p.getCurrentPoint();
p.lineTo(point.x + 20.0f, point.y + 5.0f);
// Line from
C to D
point = (Point2D.Float)p.getCurrentPoint();
p.lineTo(point.x - 20.0f, point.y + 5.0f);
// Line from
D to E
point = (Point2D.Float)p.getCurrentPoint();
p.lineTo(point.x - 5.0f, point.y + 20.0f);
// Line from
E to F
point = (Point2D.Float)p.getCurrentPoint();
p.lineTo(point.x - 5.0f, point.y - 20.0f);
// Line from
F to g
p.closePath();
// Line from
G to start
return p;
// Return the
path
}
private static GeneralPath p;
// Star path
}
Directory "StarApplet 1"
You can now define an applet that draw stars:
import javax.swing.*;
import java.awt.*;
@SuppressWarnings("serial")
public class StarApplet extends JApplet {
// Initialize the applet
@Override
public void init() {
StarPane pane = new StarPane(); // Pane containing stars
getContentPane().add(pane);
// BorderLayout.CENTER is
default position
}
Search WWH ::




Custom Search