The Rendering Pipeline
One of the strengths of the 2D API is that shapes, text, and
images are manipulated in many of the same ways. In this section, we’ll
describe what happens to shapes, text, and images after you give them to a
Graphics2D object.
Rendering is the process of taking some collection of
shapes, text, and images and figuring out how to represent them by
coloring pixels on a screen or printer. Graphics2D supports four rendering
operations:
Draw a shape’s outline with the
draw()method.Fill a shape’s interior with the
fill()method.Draw some text with the
drawString()method.Draw an image with any of the many forms of the
drawImage()method.
The graphics context represented by a Graphics2D object holds the following
properties, whose values are controlled by corresponding accessor
methods—for example, getFont() and
setFont():
- Paint
The current paint (an object of type
java.awt.Paint) determines what color or pattern will be used to fill a shape. This affects the drawing of shape outlines and text as well. You can change the current paint usingGraphics2D’ssetPaint()method. Note that theColorclass implements thePaintinterface, so you can passColors tosetPaint()if you want to use solid colors.- Stroke
Graphics2Duses the stroke to determine how to draw the outline of shapes that are passed to itsdraw()method. In graphics terminology, to “stroke” a shape means to take a path defined by the shape and effectively trace it with a pen or brush of a certain size and characteristics. ...