Java Reference
In-Depth Information
Note that we have to cast the values returned by the getX() and getY() members of the Point2D
object as they are returned as type double . It is generally more convenient to reference the x and y
fields directly as we do in the rest of the code.
We change the drawing color to blue so that you can see quite clearly the lines we are drawing. We use
the setLocation() method for the point objects to move the point on each rectangle to successive
corners, and draw a line at each position. The caption also appears in blue since that is the color in
effect when we call the drawString() method to output the text string.
Arcs and Ellipses
There are shape classes defining both arcs and ellipses. The abstract class representing a generic ellipse is:
Class
Description
Ellipse2D
This is the abstract base class for the Ellipse2D.Double and
Ellipse2D.Float classes that define ellipses. An ellipse is defined by
the top-left corner, width and height of the rectangle that encloses it.
The class representing an elliptic arc is:
Class
Description
Arc2D
This is the abstract base class for the Arc2D.Double and Arc2D.Float
classes that define arcs as a portion of an ellipse. The full ellipse is defined by
the position of the top-left corner and the width and height of the rectangle that
encloses it. The arc length is defined by a start angle measured in degrees anti-
clockwise relative to the horizontal axis of the full ellipse, plus an angular extent
measured anti-clockwise from the start angle in degrees. An arc can be OPEN ,
which means the ends are not connected; CHORD , which means the ends are
connected by a straight line, or PIE which means the ends are connected by
straight lines to the center of the whole ellipse. These constants are defined in
Arc2D .
Arcs and ellipses are closely related since an arc is just a segment of an ellipse. To define an ellipse you
supply the data necessary to define the enclosing rectangle - the coordinates of the top-left corner, the
width, and the height. To define an arc you supply the data to define the ellipse, plus additional data
that defines the segment that you want. The seventh argument to the arc constructor determines the
type, whether OPEN , CHORD , or PIE .
Search WWH ::




Custom Search