
CHAPTER 9
Thejava.awt Package
The java.awt package is the main package of the AWT, or Abstract Windowing
Toolkit. It contains classes for graphics, including the Java 2D graphics capabilities
intr oduced in the Java 2 platform, and also defines the basic graphical user inter-
face (GUI) framework for Java. java.awt also includes a number of heavyweight
GUI objects, many of which have been superseded by the javax.swing package.
java.awt also has a number of important subpackages.
The most important graphics classes in java.awt ar e Graphics and its Java 2D exten-
sion, Graphics2D. These classes repr esent a drawing surface, maintain a set of draw-
ing attributes, and define methods for drawing and filling lines, shapes, and text.
Classes that repr esent graphics attributes include Color, Font, Paint, Stroke, and Com-
posite. The Image class and Shape inter face repr esent things that you can draw using
a Graphics object and the various graphics attributes. Figure 9-1 shows the graphics
classes of this package.
The most important class for GUIs is Component, which repr esents a single graphi-
cal element in a GUI. Container is a kind of component that can contain other com-
ponents. The LayoutManager inter face and its various implementations are used to
position components within their containers. Figure 9-2 shows the GUI classes of
this package, and Figure 9-3 shows the event, exception, and security ...