CONTENTS | PREV | NEXT | Java 2D API |
CHAPTER 2 |
Graphics2D Context |
The Java 2D rendering process is controlled through the Graphics2D object and its state attributes. Graphics2D extends java.awt.Graphics to provide more sophisticated control over the presentation of shapes, text, and images.For example, the Graphics2D state attributes enable you to apply line styles and fancy fill attributes to an object when it is rendered. Line style characteristics are encapsulated by the Stroke interface. BasicStroke implements the Stroke interface to support line style attributes such as the line width, end-cap style, segment join-style, and the dashing pattern. Similarly, fill characteristics are encapsulated by the Paint interface. Color, GradientPaint, and TexturePaint implement the Paint interface to define different types of fills.
Through Graphics2D you can also control how overlapping objects are rendered. Compositing is the process of determining what color to render a pixel that is shared by overlapping objects. Two interfaces form the basis of the Java 2D composition model: Composite and CompositeContext. The class AlphaComposite implements the Composite interface to support a number of different composition styles.