Java Reference
In-Depth Information
without affecting any of its other aspects. In other words, it is possible to “plug in” a new
look and feel for any given component without creating any side effects in the code that
uses that component.
Java provides look-and-feels, such as metal and Nimbus, that are available to all Swing
users. The metal look and feel is also called the Java look and feel . It is a platform-inde-
pendent look and feel that is available in all Java execution environments. It is also the
default look and feel. For this reason, the default Java look and feel (metal) is used by the
examples in this chapter.
Swing's pluggable look and feel is made possible because Swing uses a modified version
of the classic model-view-controller (MVC) architecture. In MVC terminology, the model
corresponds to the state information associated with the component. For example, in the
case of a check box, the model contains a field that indicates if the box is checked or un-
checked. The view determines how the component is displayed on the screen, including any
aspects of the view that are affected by the current state of the model. The controller de-
termines how the component reacts to the user. For example, when the user clicks a check
box, the controller reacts by changing the model to reflect the user's choice (checked or
unchecked). This then results in the view being updated. By separating a component into a
model, a view, and a controller, the specific implementation of each can be changed without
affecting the other two. For instance, different view implementations can render the same
component in different ways without affecting the model or the controller.
Although the MVC architecture and the principles behind it are conceptually sound, the
high level of separation between the view and the controller was not beneficial for Swing
components. Instead, Swing uses a modified version of MVC that combines the view and
the controller into a single logical entity called the UI delegate . For this reason, Swing's
approach is called either the model-delegate architecture or the separable model architec-
ture. Therefore, although Swing's component architecture is based on MVC, it does not use
a classical implementation of it. Although you won't work directly with models or UI del-
egates in this chapter, they are, nevertheless, present behind the scene.
As you work through this chapter, you will see that even though Swing embodies very
sophisticated design concepts, it is easy to use. In fact, one could argue that Swing's ease
of use is its most important advantage. Simply stated, Swing makes manageable the often
difficult task of developing your program's user interface. This lets you concentrate on the
GUI itself, rather than on implementation details.
Ask the Expert
Search WWH ::




Custom Search