Java Reference
In-Depth Information
GUIs. The AWT interfaces talk directly to the underlying graphical operating sys-
tem interfaces. Since AWT is ported to every Java environment, any Java applica-
tion that uses AWT can display GUIs in any Java environment, although the look
and feel of the application may vary.
So far it sounds good, but because of several problems, AWT has been regarded
by many as the weakest part of the original Java environment. The primary prob-
lem is that AWT was designed to the lowest common denominator of graphical en-
vironments. Important capabilities (e.g., tabbed views, spinners, complex layouts)
required by graphical applications are not available in AWT.
Sun improved on AWT with the newer Java Foundation Classes (JFC), released
as a patch to the Java Development Kit (JDK) 1.1. These APIs are grouped in a
package named for the code name for the internal development project at Sun
(Swing). The Swing package is meant to replace the AWT. Most applications that
have Java UI's use Swing instead of AWT.
Applications that use Swing have access to more control over the user interface.
For example, an application can now manage borders around graphical compo-
nents, and components do not all need to be rectangular. Swing brings with it a
more robust event model and widgets not available in AWT, such as table and tree
control. Swing is not dependant on the native components and, therefore, the look
and feel of Swing applications are independent of the platform.
For development of new Java applications, Swing and JFC are clearly the best
choices available. Yet the learning curve is relatively steep if you have no experience
in GUI development. Following are some of the basic concepts and knowledge you
need to get started.
The javax.swing and javax.swing.event packages contain most of the classes
you will need, but you will also use java.awt and java.awt.event packages extensively
because Swing is built on or uses AWT.
The JFrame class is used to create the main frame window of an application.
You can add a menu bar to it using JMenuBar or add a tool bar using JToolBar. You
can populate the frame with buttons, combo boxes, text fields, and other GUI ele-
ments. A layout manager is generally used to control the appearance. Various lay-
out managers are defined in java.awt.
Figure 12.1 describes how these various components combine to create a Swing
user interface.
Search WWH ::




Custom Search