
CHAPTER 2
Swing and AWT
Ar chitecture
The Abstract Windowing Toolkit (AWT) provides basic facilities for creating graphi-
cal user interfaces (GUIs), and also for drawing graphics, as we’ll discuss in a later
chapter. AWT has been a core part of Java since Java 1.0. The GUI features of AWT
ar e layer ed on top of the native GUI system of the underlying platform. In other
words, when you create a graphical push button with AWT, AWT creates a Win-
dows push button, or a Macintosh push button, or a Motif push button, or what-
ever, depending on the platform on which the application is running. In Java 1.1,
AWT was extended to allow the creation of “lightweight” GUI components that do
not have corresponding native GUI components behind them.
Swing is a new GUI toolkit that is available as a core part of the Java 2 platform
and also as an extension to Java 1.1. Swing is an extension of the AWT toolkit, not
an entirely new toolkit. All of the GUI components provided by Swing are
lightweight components, so they do not rely on the underlying native GUIs. The
result is that Swing is more portable, making it much easier to write graphical
applications that behave the same on all platforms. Swing is also larger and more
compr ehensive than AWT. In addition to a complete and powerful set of GUI com-
ponents, Swing provides a number of utilities that make it easier to write graphical
applications.
Swing offers ...