Introducing the AWT:
Working with Windows,
Graphics, and Text
he Abstract Window Toolkit (AWT) was introduced in Chapter 21, where it was used in
several example applets. This chapter begins its in-depth examination. The AWT contains
numerous classes and methods that allow you to create and manage windows. It is also
the foundation upon which Swing is built. The AWT is quite large and a full description would
easily fill an entire topic. Therefore, it is not possible to describe in detail every AWT class, method,
or instance variable. However, this and the following two chapters explain the basic techniques
needed to use the AWT effectively when creating your own applets or stand-alone GUI-based
applications. From there, you will be able to explore other parts of the AWT on your own. You will
also be ready to move on to Swing.
In this chapter, you will learn how to create and manage windows, manage fonts, output
text, and utilize graphics. Chapter 24 describes the various controls, such as scroll bars and
push buttons, supported by the AWT. It also explains further aspects of Java's event handling
mechanism. Chapter 25 examines the AWT's imaging subsystem and animation.
Although a common use of the AWT is in applets, it is also used to create stand-alone
windows that run in a GUI environment, such as Windows. For the sake of convenience,
most of the examples in this chapter are contained in applets. To run them, you need to use
an applet viewer or a Java-compatible web browser. A few examples will demonstrate the
creation of stand-alone, windowed programs.
One other point before beginning. Today, most Java programs employ user interfaces
based on Swing. Because Swing provides richer implementations than does the AWT of
some common GUI controls, such as buttons, lists, and check boxes, it is easy to jump to
the conclusion that the AWT is no longer important, that it has been superseded by Swing.
This assumption is, however, quite wrong. As mentioned, Swing is built on top of the AWT.
Thus, many aspects of the AWT are also aspects of Swing. Furthermore, many AWT classes
are used either directly or indirectly by Swing. Finally, for some types of small programs
(especially small applets) that make only minimal use of a GUI, using the AWT rather than
Swing still makes sense. Therefore, even though most interfaces today will be based on
Swing, a solid knowledge of the AWT is still required. Simply put, you can't be a great Java
programmer without knowing the AWT.
Search WWH :