Java Reference
In-Depth Information
event; this was tedious and error prone. Before long, a new delegation event model was in-
troduced, which is still with us. In this model, events are given only to classes that request
them, which is done by registering a listener . This is discussed in Action Handling: Making
Buttons Work and shown in Example 14-3 . At the same time, the language was extended
slightly to include the notion of inner classes. An inner class is simply a class whose defini-
tion is contained inside the body of another class. We use examples of two types of inner
classes here; for details on the half-dozen different categories of inner classes, the reader is
referred to Java in a Nutshell .
Most of the GUI construction techniques in this chapter can be done for you, in some cases
more quickly, by an integrated development environment (IDE). I believe, however, that un-
derstanding what goes on inside the code should be a prerequisite for being allowed to use an
IDE. Those who disagree may be inclined to skip this chapter, go press a few buttons, and
have the computer do the work for them. But you should at least skim this chapter to see
what's going on so that you'll know where to look when you need it later.
See Also
Before you unleash your GUI application upon the world, make sure to read the official Java
Look and Feel Design Guidelines (Addison-Wesley). This work presents the views of a large
group of human factors and user-interface experts at Sun/Oracle who have worked with the
Swing GUI package since its inception; they tell you how to make it work well.
Displaying GUI Components
Problem
You want to create some GUI components and have them appear in a window.
Solution
Create a JFrame and add the components to its ContentPane .
Discussion
The older AWT had a simple Frame component for making main windows; this allowed you
to add components directly to it. “Good” programs usually created a panel to fit inside and
Search WWH ::




Custom Search