November 2004
Intermediate to advanced
1024 pages
27h 50m
English
The draw operation of the Graphics2D class draws the boundary of a shape by using the currently selected stroke. By default, the stroke is a solid line that is one pixel wide. You can select a different stroke by calling the setStroke method. You supply an object of a class that implements the Stroke interface. The Java 2D API defines only one such class, called BasicStroke. In this section, we look at the capabilities of the BasicStroke class.
You can construct strokes of arbitrary thickness. For example, here is how you draw lines that are 10 pixels wide.
g2.setStroke(new BasicStroke(10.0F)); g2.draw(new Line2D.Double(. . .));
When a stroke is more than a pixel thick, then the end of the stroke can have different styles. Figure 7-12 ...
Read now
Unlock full access