Java Reference
In-Depth Information
Note The Swing components don't support the original JDK 1.0 event model. They no longer use the
public boolean handleEvent(Event) method and all its helper methods. If you need to convert an
AWT program that uses the JDK 1.0 event model to one that uses the Swing components, you'll need to
convert the program to use the delegation-based event model, in addition to changing the component set.
Although directly porting old Java AWT programs (or programmers!) to Swing programs is
done most easily by continuing to use the delegation-based event model, this solution is rarely
the best one. Besides supporting the delegation-based event model, the Swing components
provide other, more efficient ways of dealing with events for components. In Chapter 2, you'll
explore the delegation-based event model and look at the other ways of managing event handling.
In addition to the delegation-based event-handling support, the Swing components use
the Model-View-Controller (MVC) design to separate their user interfaces from their underlying
data models. Using the MVC architecture provides yet another way of event handling with a
Swing component. While MVC might be new to most developers, the basic constructs use the
delegation-based event model. MVC provides the optimal way of working with the Swing
components. You'll find an overview of the MVC architecture in Chapter 3.
Besides all the support for extended event handling with the Swing classes, these classes
share the need to use a layout manager for positioning components on the screen. In addition
to using the layout managers that come with AWT, you can use other layout managers that
come with the Swing classes. In Chapter 10, you'll learn about both the AWT and Swing layout
managers.
Undo Framework
Situated within the javax.swing class hierarchy are the javax.swing.undo classes. These classes
offer a framework for supporting undo and redo capabilities within Java programs. Instead of
creating the basic framework yourself, the framework is provided as part of the Swing classes.
Although the undo classes don't use anything directly outside their package, the Swing text
components use the undo functionality. Chapter 21 provides a detailed explanation of undo.
SwingSet Demonstration
As part of the demo/jfc directory with the Java 2 platform, you have available a Swing demon-
stration program called SwingSet2 . This program provides a quick preview of the majority of
the Swing capabilities. All the source code is included, so if you see something you like and are
interested in learning how it was done, just dig through the code to find the appropriate lines.
With the Java 2 platform, you start up this demonstration from the SwingSet2 directory
with the java -jar SwingSet2.jar command. After starting the SwingSet2 demonstration, you
see the opening screen, as shown in Figure 1-20.
 
Search WWH ::




Custom Search