In previous chapters, we looked at the components and component architecture of graphical user interfaces (GUIs) using Java’s Swing and AWT packages. Now, we’re going to drop down a level and look at the procedural APIs for rendering graphics in Java applications. These APIs are used by components to paint themselves on the screen and to display icons and graphics. This chapter goes into some detail about Java’s sophisticated 2D, resolution-independent drawing API and the core tools for loading and displaying images. In the next chapter, we’ll explore dynamic image-processing tools in more detail and look at the classes that let you generate and modify image data, pixel by pixel.
The classes you’ll use for drawing come from
java.awt.print. Collectively, these classes make up most of the 2D
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
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 ...