Java Reference
In-Depth Information
Chapter 17
• Introduce Java classes for creating Graphical User Interfaces.
• Learn to think of a program as responding to events.
GUI stands for Graphical User-Interface . GUIs consist basically of windows on
your monitor that you use to communicate with an application. In this chapter, we
introduce the basics for constructing GUIs in Java programs. The web page for
this lesson on the CD contains links to tutorials on GUIs and to the API specs for
the Java packages that deal with GUIs.
The basic classes for constructing a GUI are in package java.awt (abstract
window toolkit) and in the newer package javax.swing , called the Java
Foundation Classes ( Swing , for short). The names of many (but not all) classes
in package javax.swing are the names of their counterparts in package java.-
awt but preceded with a J . For example, Button is an awt class and JButton is
the corresponding Swing class.
The classes in javax.swing provide more flexibility and function than those
in java.awt . The components in javax.swing are lightweight , while those in the
awt are heavyweight (these terms are explained in Sec. 17.2.6). When possible,
use the Swing classes.
Throughout this chapter, we explain and then summarize basic GUI methods.
There are other methods that we do not have space to discuss. Get in the habit of
perusing the specs so that you have some idea about how the GUI classes are
structured and some familiarity with their methods.
Further, the ProgramLive CD contains far more material, with pictures and
diagrams in color, than we can cover here. Watching the CD, rather than just read-
ing this chapter, will be more informative as well as more enjoyable.
You can obtain source files for all programs in this chapter from the CD.
All the exam-
ple programs
used in this
chapter can be
obtained from
the first foot-
note on lesson
page 17-1.
Search WWH ::

Custom Search