Graphics Stroking

The Graphics2D method setStroke() is yet another method for changing the graphics context. We will now examine graphics stroking in greater detail.

Whenever a shape is stroked, it is as if a virtual pen draws an outline around the shape. The virtual pen has a characteristic style defining a set of shape primitives that are combined to make the desired effect. In Java 2D, the pen style is specified in a BasicStroke object. BasicStroke implements the Stroke interface and is intended to be used as an argument to the setStroke() method of the Graphics2D object.

The BasicStroke object represents the attributes for line width, endcap, and join style in addition to attributes for specifying different types of dash patterns. Setting ...

Get Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.