Java Reference
In-Depth Information
provide much-improved alternatives to components defined by classes in java.awt . You look into the JBut-
ton class in the Swing set that defines a button, rather than the Button class in java.awt . However, the
Swing component classes are generally derived from, and depend on, fundamental classes that are defined
within the java.awt package, so you can't afford to ignore these.
The Swing classes are part of a more general set of GUI programming capabilities that are collectively
referred to as the Java Foundation Classes , or JFC for short. JFC covers not only the Swing component
classes, such as those defining buttons and menus, but also classes for 2D drawing from the java.awt.geom
package and classes that support drag-and-drop capability in the java.awt.dnd package. The JFC also in-
cludes an application program interface (API) defined in the javax.accessibility package that allows
applications to be implemented that provide for users with disabilities.
The Swing component classes are more flexible than the component classes defined in the java.awt
package because they are implemented entirely in Java. The java.awt components depend on native code
to a great extent and are, therefore, restricted to a “lowest common denominator" set of interface capab-
ilities. Because Swing components are pure Java, they are not restricted by the characteristics of the plat-
form on which they run. Apart from the added functionality and flexibility of the Swing components, they
also provide a feature called pluggable look-and-feel that makes it possible to change the appearance of a
component. You can programmatically select the look-and-feel of a component from those implemented as
standard, or you can create your own look-and-feel for components if you want. The pluggable look-and-
feel of the Swing components has been facilitated by designing the classes in a particular way, called the
Model-View-Controller architecture.
Model-View-Controller (MVC) Architecture
The design of the Swing component classes is loosely based on something called the Model-View-Controller
architecture , or MVC . This is not of particular consequence in the context of applying the Swing classes, but
it's important to be aware of it if you want to modify the pluggable look-and-feel of a component. MVC is
not new and did not originate with Java. In fact, the idea of MVC emerged some time ago within the context
of the SmallTalk programming language. MVC is an idealized way of modeling a component as three sep-
arate parts:
• The model that stores the data that defines the component
• The view that creates the visual representation of the component from the data in the model
• The controller that deals with user interaction with the component and modifies the model and/or
the view in response to a user action as necessary
Figure 17-1 illustrates the relationships between the model, the view, and the controller.
FIGURE 17-1
 
 
Search WWH ::




Custom Search