Java Reference
In-Depth Information
// Define open arc as an upper segment of an ellipse
Arc2D.Double top = new Arc2D.Double(position.x, position.y,
width, height,
start, extent,
Arc2D.OPEN);
// Define open arc as lower segment of ellipse shifted up
relative to 1st
Arc2D.Double bottom = new Arc2D.Double(
position.x, position.y - height +
diameter,
width, height,
start + 180, extent,
Arc2D.OPEN);
// Create a circle centered between the two arcs
Ellipse2D.Double circle1 = new Ellipse2D.Double(
position.x + width/2 - diameter/
2,position.y,
diameter, diameter);
// Create a second circle concentric with the first and half the
diameter
Ellipse2D.Double circle2 = new Ellipse2D.Double(
position.x + width/2 - diameter/4, position.y +
diameter/4,
diameter/2, diameter/2);
// Draw all the shapes
g2D.setPaint(Color.BLACK);
// Draw in black
g2D.draw(top);
g2D.draw(bottom);
g2D.setPaint(Color.BLUE);
// Draw in blue
g2D.draw(circle1);
g2D.draw(circle2);
g2D.drawString("Arcs and ellipses", 80, 100);
// Draw some text
}
Directory "Sketcher 3 drawing arcs and ellipses"
Running Sketcher with this version of the paint() method in SketcherView produces the window
shown in Figure 19-11 .
FIGURE 19-11
 
 
Search WWH ::




Custom Search