Java Reference
In-Depth Information
To draw an ellipse, you specify its bounding box (see
Figure 23
) in the same way that
you would specify a rectangle, namely by the x- and y-coordinates of the top-left
corner and the width and height of the box.
However, there is no simple
Ellipse
class that you can use. Instead, you must use
one of the two classes
Ellipse2D.Float
and
Ellipse2D.Double
, depending
on whether you want to store the ellipse coordinates as single- or double-precision
floating-point values. Because the latter are more convenient to use in Java, we will
always use the
Ellipse2D.Double
class. Here is how you construct an ellipse:
65
66
Figure 23
An Ellipse and Its Bounding Box
Ellipse2D.Double ellipse = new Ellipse2D.Double(x, y,
width, height);
The class name
Ellipse2D.Double
looks different from the class names that you
have encountered up to now. It consists of two class names
Ellipse2D
and
Double
separated by a period (
.
). This indicates that
Ellipse2D.Double
is a so-called
inner class inside
Ellipse2D
. When constructing and using ellipses, you don't
actually need to worry about the fact that
Ellipse2D.Double
is an inner classČ
just think of it as a class with a long name. However, in the
import
statement at the
top of your program, you must be careful that you import only the outer class: