
CHAPTER 4
Graphics with AWT
and Java 2D
Java 1.0 and Java 1.1 included basic graphics capabilities as part of the AWT
(Abstract Windowing Toolkit). In the Java 2 platform, these capabilities have been
gr eatly enhanced with the introduction of Java 2D. While Java 2D is part of the JFC
(the Java Foundation Classes), the Java 2D API is implemented in the same
java.awt package as the original Java graphics classes.
This chapter begins by documenting the original Java graphics model, which is still
requir ed for Java 1.1 applications, applets, and Personal Java applications. The
chapter then moves on to detail the enhanced features provided by Java 2D. This
chapter can provide only an introduction to the various features of Java 2D; for
mor e complete information, see Java 2D Graphics,byJonathan Knudsen
(O’Reilly).
Graphics Before Java 2D
All graphics operations in Java are per formed using a java.awt.Graphics object.
The
Graphics object serves three purposes:
•Itrepr esents the drawing surface. A
Graphics object is used to draw into a
java.awt.Component on the screen, to draw into an off-scr een java.awt.-
Image,ortosend graphics to a printer.
•Itmaintains the current state of graphics attributes, such as the current draw-
ing color, font, and clipping region.
•Itdefines methods that perfor m various graphics operations, such as drawing
lines, rendering strings of text, and copying the content of
Image objects ...