Java Reference
In-Depth Information
In object-oriented terms, each of the three logical parts for a component — the model, the view, and the
controller — is ideally represented by a different class type. In practice this turns out to be difficult because
of the dependencies between the view and the controller. Because the user interacts with the physical repres-
entation of the component, the controller operation is highly dependent on the implementation of the view.
For this reason, the view and controller are typically represented by a single composite object that corres-
ponds to a view with an integrated controller. In this case the MVC concept degenerates into the document/
view architecture that I introduced when I discussed the Observable class and Observer interface. Sun calls
it the Separable Model architecture , as illustrated in Figure 17-2 .
FIGURE 17-2
The Swing components provide for a pluggable look-and-feel by making the visual appearance of a com-
ponent and the interface to the user the responsibility of an independent object called the UI delegate . This
is the view+controller part of the MVC model. Thus, a different UI delegate can provide a component with
a new look-and-feel.
The details of how you modify the look-and-feel of a component are beyond the scope of this topic, but
I introduce how you can set one of the standard looks-and-feels that are distributed with the Java Develop-
ment Kit (JDK). It is as well to be aware of the MVC architecture on which the Swing components are based
because it appears quite often in the literature around Java, and you may want to change the look-and-feel
of a component at some time.
CREATING A WINDOW
A basic window in Java is represented by an object of the Window class, which is defined in the java.awt
package. Objects of the Window class are hardly ever used directly because borders and a title bar are fairly
basic prerequisites for a typical application window, and this class provides neither. The library class JFrame
that is defined in the javax.swing package is a much more useful class for creating a window because, in
 
 
Search WWH ::




Custom Search