These objects are a necessary part of every Java 2D drawing operation.
Shapes A
shape in Java 2D is a boundary which defines an inside and an outside.
Pixels inside the shape are affected by the drawing operation, those outside are not. Trying to fill a straight
line segment will result in no pixels being affected, as such a shape does not contain any pixels itself. Instead, a thin
rectangle must be used so that the shape contains some pixels.
Paints A
paint generates the
colors to be used for each pixel of the fill operation. The simplest paint is '''''', which generates the same color for all pixels. More complicated paints may produce gradients,
images, or indeed any combination of colors. Filling a circular shape using the color yellow results in a solid yellow circle, while filling the same circular shape using a paint that generates an image produces a circular cutout of the image.
Composites During any drawing operation, there is a
source (the pixels being produced by the paint) and a
destination (the pixels already onscreen). Normally, the source pixels simply overwrite the destination pixels, but the
composite allows this behavior to be changed. The composite, given the source and destination pixels, produces the final result that ultimately ends up onscreen. The most common composite is '''''', which can treat the pixels being drawn as partially transparent, so that the destination pixels show through to some degree.
Filling To
fill a shape, the first step is to identify which pixels fall inside the shape. These pixels will be affected by the fill operation. Pixels that are partially inside and partially outside the shape may be affected to a lesser degree if
anti-aliasing is enabled. The paint is then asked to generate a color for each of the pixels to be painted. In the common case of a solid-color fill, each pixel will be set to the same color. The composite takes the pixels generated by the paint and combines them with the pixels already onscreen to produce the final result. ==Advanced objects==