Fill Attributes and Painting

Assigning material for painting is done by creating a Paint object (specifically, an object implementing the Paint interface) and adding it to the Graphics2D context with the setPaint() method. As you will see next, three general types of Paint objects already exist and are easily instantiated. Any of these can readily be used as arguments to setPaint(). Before going into these three general types, it is worthwhile to understand the Paint interface and how it relates to a second interface, the PaintContext interface. An understanding of these two interfaces will be useful when we discuss custom painting later.

The Paint interface consists of a unitary method that returns a PaintContext:

 PaintContext createContext(ColorModel ...

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.