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.


2.0.1 Interfaces




Interface

Description

Composite

Defines methods to compose a draw primitive with the underlying graphics area. Implemented by AlphaComposite.

CompositeContext

Defines the encapsulated and optimized environment for a composite operation. Only of concern to programmers implementing custom compositing rules.

Paint

Extends: Transparency

Used by graphics operations to obtain the colors used to fill geometric shapes and strokes. Implemented by Color, GradientPaint and TexturePaint.

PaintContext

Defines the encapsulated and optimized environment for a paint operation. Only of concern to programmers implementing custom paint operations.

Shape

Provides a common set of methods for describing and inspecting geometric path objects. Implemented by GeneralPath.

Stroke

Converts a stroke shape to an outline shape that can be filled. Implemented by BasicStroke.

Transparency

Defines common transparency modes for implementing classes: opaque, semitransparent, and translucent. Implemented by ColorModel.


2.0.2 Classes




Class

Description

AlphaComposite

Implements: Composite

Implements basic alpha composite rules for graphics and images.

BasicStroke

Implements: Stroke

Defines rendering attributes for strokes.

GradientPaint

Implements: Paint

Provides a way to fill a shape with a linear color gradient pattern. Color changes from color C1 at point P1 to color C2 at point P2.

Graphics2D

Extends: Graphics

Fundamental class for 2D rendering in Java. Extends the original java.awt.Graphics class.

TexturePaint

Implements: Paint

Provides a way to fill a shape with a given texture. The texture used is specified as a BufferedImage.



CONTENTS | PREV | NEXT
Copyright © 1997-1998 Sun Microsystems, Inc. All Rights Reserved.