The Big Picture
The classes you’ll use for drawing come from six packages:
java.awt, java.awt.color,
java.awt.font, java.awt.geom, java.awt.image, and
java.awt.print.
Collectively, these classes make up most of the 2D API and cover the
drawing of shapes, text, and images. Figure 20-1 shows a bird’s-eye view of these
classes. There’s much more in the 2D API than we can cover in two
chapters. For a full treatment, see Jonathan Knudsen’s Java 2D
Graphics (O’Reilly).
An instance of java.awt.Graphics2D is called a
graphics context. It represents a drawing
surface—such as a component’s display area, a page on a printer, or an
offscreen image buffer. A graphics context provides methods for drawing
three kinds of graphics objects: shapes, text, and images. Graphics2D is called a graphics context because
it also holds contextual information about the drawing area. This
information includes the drawing area’s clipping region, painting color,
transfer mode, text font, and geometric transformation. If you consider the drawing
area to be a painter’s canvas, you might think of a graphics context as an
easel that holds a set of tools and marks off the work area.

Figure 20-1. Graphics classes of the 2D API
There are four ways to acquire a Graphics2D object. The following list describes
them in order from the most common to the least:
- From AWT or Swing as the result of a painting request on a component ...