Java Reference
In-Depth Information
Line 23 creates the
comp2D
object used for all 2D drawing operations. It's a cast of
the
Graphics
object that represents the panel's visible surface.
n
Lines 32-34 create a
BasicStroke
object that represents a line width of 2 pixels
and then makes this the current stroke with the
setStroke()
method of
Graphics2D
.
n
Lines 35-40 use two nested
for
loops to create waves from individual arcs.
n
Lines 42-43 create a gradient fill pattern from the color green at 0, 0 to orange at
50, 50. The last argument to the constructor,
true
, causes the fill pattern to repeat
itself as many times as needed to fill an object.
n
Line 44 sets the current gradient fill pattern using the
setPaint()
method and the
gp
object just created.
n
Lines 45-63 create the polygon shaped like the state of Florida and draw it. This
polygon is filled with a green-to-orange gradient pattern.
n
Line 63 sets the current color to black. This replaces the gradient fill pattern for the
next drawing operation because colors are also fill patterns.
n
Line 65 creates a new
BasicStroke()
object with no arguments, which defaults to
a 1-pixel line width.
n
Line 66 sets the current line width to the new
BasicStroke
object
pen2
.
n
Lines 68-70 create three ellipses at 235, 140; 225, 130; and 245, 130. Each is 15
pixels wide by 15 pixels tall, making them circles.
n
Figure 13.9 shows the application running.
FIGURE 13.9
The
Map
application.
13