An essential and very popular part of Java has always been its
graphical user interface (GUI) capabilities. The above applet, for
example, illustrates some of the basic aspects of a GUI program.
The display shows a large panel area that holds various components.
These components include buttons for control, text fields for inputs,
and a text area for output.
From version 1.0 the standard JVM included the java.awt
package and sub-packages that provided the classes to develop user
interfaces and to do drawing. However, the original graphics capabilities
in Java 1.0 and 1.1 were quite limited. This led to some disenchantment
with Java for standalone client applications.
With version 1.2 came the addition of the so-called Swing
packages that greatly expanded the range and flexibility of Java
GUI design. Swing components include tables, buttons with icons,
radio buttons, and more. (Sun's Visual
Index to the Swing Components shows whats available.)
In this chapter we give an introduction to the basics of programming
a user interface and discuss both the AWT and Swing. The sections
- AWT discusses the basic level GUI class
hierarchy in Java and its limitations.
- Swing gives an overview of the Swing
- Containers are components that
hold other components. A GUI program always includes at least
one top level container and usually several sub-containers.
- Components discusses basic GUI
- Text display with components like
JTextField and JTextArea.
- Simple Drawing discusses how to use
a panel component as a drawing board.
- Drawing Polygons - illustrates techniques
taken to much higher level by Java2D.
- Drawing Text - how to display text on
a drawing panel
- Images - basics of reading in an image
file and displaying it on a panel.
The Chapter 6:
Supplement section provides more examples of a purely AWT component
approach to GUI design and the Java2D graphics package.