Java Reference
In-Depth Information
text fields and text areas. As seen in the diagram above, the AWT includes the
basic atomic components needed to create fairly complete, if not particularly
attractive, GUI displays.
6.3 Swing: lightweight beats heavyweight
As mentioned above, the graphics prior to Java 1.2 included only the AWT in the
core language packages and so did not provide for thrilling user interfaces. The
AW T components came with a number of shortcomings. For example, simply
creating a subclass of the Button class to allow for a custom button that displays
an icon was and remains impractical. Other AWT visual components had similar
limitations. Java programs based on the AWT became known for their bland
appearance and minimal capabilities.
The basic problem is that the AWT components are closely tied to the so-
called peer component classes written in native code for the local operating
system's graphical interface. This means that Java portability required a lowest
common denominator approach in which no visible component could provide
more capability than what was available on all platforms. This resulted in very
limited options in the appearance and performance of the components. These
basic AWT components are called heavyweight because they must drag along all
the peer component baggage.
Afar more flexible approach is to open a heavyweight top-level class, such as
a window frame, and then simply draw all the visible sub-components without
involving any other local peer components. Such lightweight components are
very flexible, especially when combined with the more powerful event handling
structure that came with Java version 1.1 ( events , such as mouse clicks, are
discussed in Chapter 7).
The Swing set of classes (available in the javax.swing and related packages)
consists primarily of lightweight components. Swing first became available as an
independent class library that worked with Java version 1.1. Later, its packages
were included in Java 1.2. It is now generally recommended that programmers
use Swing for all serious graphics development on desktop platforms. When
developing programs for platforms with limited memory and display capability,
such as those targeted by J2ME, the pure AWT framework remains a viable
choice. (The Web Course Chapters 6 and 7 provide an introduction to graphics
programming with the AWT.)
Note that the Swing package names start with javax rather than java . The
packages whose names start with java are often referred to as the core Java
language packages. The javax package hierarchy was invented to include “stan-
dard extensions.” There are now dozens of javax packages. So while Swing is
not core, it is considered a standard part of the language and is included with the
Standard (J2SE) and Enterprise (J2EE) editions for all platforms. (A number of
javax packages, such as the javax.comm package discussed in Chapter 23,
Search WWH ::




Custom Search