Java Reference
In-Depth Information
CHAPTER 10
Graphical User Interfaces
Graphical user interfaces, or GUIs, represent an excellent example of software
modularity and reuse. GUIs are almost always assembled from libraries of prede-
fined building blocks. To Motif programmers on Unix systems, these GUI building
blocks are known as widgets . To Windows programmers, they are known as con-
tr ols . In Java, they are known as by the generic term components , because they
are all subclasses of java.awt.Component . *
In Java 1.0 and 1.1, the standard library of GUI components was the Abstract Win-
dowing Toolkit (AWT)—the package java.awt and its subpackages. In addition to
GUI components, the AWT includes facilities for drawing graphics, performing cut-
and-paste-style data transfer, and other related operations. On most platforms,
AWT components are implemented using the operating-system native GUI system.
That is, AWT components are implemented on top of Windows controls on Win-
dows operating systems, on top of Motif widgets on Unix systems, and so on. This
implementation style led to a least-common denominator toolkit, and, as a result,
the AWT API is not as complete and full featured as it should be.
Java 1.2 introduced a new library of GUI components known as Swing. Swing
consists of the javax.swing package and its subpackages. Unlike the AWT, Swing
has a platform-independent implementation and a state-of-the-art set of features.
Although Swing first became a core part of the Java platform in Java 1.2, a version
of Swing is available for use with Java 1.1 platforms. Swing has largely replaced
the AWT for the creation of GUIs, so we'll focus on Swing in this chapter. Note
that Swing defines a new, more powerful set of GUI components but retains the
same underlying GUI programming model used by the AWT. Thus, if you learn to
create GUIs with Swing components, you can do the same with AWT components.
* Except for menu-related AWT components, which are all subclasses of java.awt.MenuComponent .
† The exception is with applets, which, for compatibility with the existing installed base of web browsers
that do not support Swing, often use AWT components.
 
Search WWH ::




Custom Search