Java Reference
In-Depth Information
the abstract window
toolkit and swing
B.1
The Abstract Window Toolkit ( AW T ) is a GUI toolkit that is supplied with all
Java systems. It provides the basic classes to allow user interfaces. These
classes can be found in the package java.awt . 1 The AWT is designed to be
portable and work across multiple platforms. For relatively simple interfaces,
the AWT is easy to use. GUIs can be written without resorting to visual devel-
opment aids and provide a significant improvement over basic terminal inter-
faces.
The Abstract Win-
dow Toolkit (AWT)
is a GUI toolkit that
is supplied with all
Java systems.
In a program that uses terminal I/O, the program typically prompts the
user for input and then executes a statement that reads a line from the termi-
nal. When the line is read, it is processed. The flow of control in this situation
is easy to follow. GUI programming is different. In GUI programming, the
input components are arranged in a window. After the window is displayed,
the program waits for an event, such as a button push, at which point an event
handler is called. This means that the flow of control is less obvious in a GUI
program. The programmer must supply the event handler to execute some
piece of code.
GUI programming
is event-driven.
Java 1.0 provided an event model that was cumbersome to use. It was
replaced in Java 1.1 by a more robust event model. Not surprisingly, these
models are not entirely compatible. Specifically, a Java 1.0 compiler will not
successfully compile code that uses the new event model. Java 1.1 compilers
will give diagnostics about Java 1.0 constructs. However, already compiled
Java 1.0 code can be run by a Java 1.1 Virtual Machine. This appendix
describes the newer event model only. Many of the classes required by the
new event model are found in the java.awt.event package.
The event model
changed in incom-
patible ways from
Java 1.0 to Java
1.1. The latter ver-
sion is described
here.
The AWT provided a simple GUI but was criticized for its lack of flair, as
well as poor performance. In Java 1.2, an improved set of components was
added in a new package called javax.swing . These components are known as
Swing . Components in Swing look much better than their AWT counterparts;
there are new Swing components that did not exist in AWT (such as sliders
and progress bars) and have many more options (such as easy tooltips and
mnemonics). Additionally, Swing provides the notion of look-and-feel, in
which a programmer can display the GUI in Windows, X-Motif, Macintosh,
platform independent (metal), or even customized style, regardless of the
underlying platform (although, because of copyright issues and perhaps bad
blood between Sun and Microsoft, Windows look-and-feel works only on
Windows systems).
Swing is a GUI
package provided
in Java 1.2 that is
built on top of the
AWT and provides
slicker components.
1. Code in this appendix uses the wild-card import directive to save space.
 
 
 
Search WWH ::




Custom Search