Java Reference
In-Depth Information
Ellipse2D.Double and Line2D.Double are classes that describe graphical shapes.
import java.awt.geom.Ellipse2D;
Drawing an ellipse is easy: Use exactly the same draw method of the Graphics2D
class that you used for drawing rectangles.
g2.draw(ellipse);
To draw a circle, simply set the width and height to the same values:
Ellipse2D.Double circle = new Ellipse2D.Double(x, y,
diameter, diameter);
g2.draw(circle);
Figure 24
Basepoint and Baseline
66
67
Notice that ( x, y ) is the top-left corner of the bounding box, not the center of the
circle.
To draw a line, use an object of the Line2D.Double class. A line is constructed by
specifying its two end points. You can do this in two ways. Simply give the x- and
y-coordinates of both end points:
Line2D.Double segment = new Line2D.Double(x1, y1, x2,
y2);
Or specify each end point as an object of the Point2D.Double class:
Point2D.Double from = new Point2D.Double(x1, y1);
Point2D.Double to = new Point2D.Double(x2, y2);
Search WWH ::




Custom Search