
Recall the code that we just used to draw the outline of a circle. The draw()
method has to draw the outline of the circle using only the fill() method. If it
simply calls
fill() on the circle, it ends up creating a solid disk, not the outline of
a circle. So instead,
draw() first passes the circle to the createStrokedShape()
method of the BasicStroke object we’ve specified. createStrokedShape() retur ns
a new shape: a circle of radius 105, minus a concentric circle of radius 95. The
interior of this shape is the area between the two circles, a region that always has
a width of 10 units. Now
draw() can call fill() on this stroked shape to draw the
10-unit-wide outline of the original circle. (We’ll discuss the
fill() operation and
the graphics attributes that it uses in the next section.)
Paint
As we’ve just seen, the Java 2D Stroke attribute turns the task of drawing a line
into the task of filling an area. Prior to Java 2D, an area could be filled only with a
solid color, specified by passing a
Color object to the setColor() method of a
Graphics object. In Java 2D, this color attribute has been generalized to a paint
attribute: you pass a
Paint object to the setPaint() method of a Graphics2D
object. The specified Paint object is used to generate the pixel values used to fill
ar eas.
The most common way to fill an area, however, is still to use a solid color. So
another change in Java 2D is that the
java.awt.Color ...