Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
More action with Struts 2
In a recent review of Struts 2 in Action, JW Blogger Oleg Mikheev notes that Struts 2 is "just a collection of extensions built upon WebWork, which is ultimately
the right thing to learn before starting a Struts 2 project." While Struts 2 has some architectural flaws, Oleg calls WebWork
well-designed, well-tested, and reliable. What are your experiences using Struts 2 and WebWork?
Also see "Hello World the WebWork way," a JavaWorld excerpt from WebWork in Action, by Patrick Lightbody and Jason Carreira.
| Memory Analysis in Eclipse |
| Enterprise AJAX - Transcend the Hype |
This construction turns out to be a powerful design feature. It encourages reuse rather than redesign. Because your keyboard's keys were designed that way, it's possible to reuse the button mechanism design, and replace the key tops to create a new key rather than designing each key from scratch. This creates a substantial savings in design effort and time.
Not surprisingly, similar benefits occur when this technique is applied to software development. One commonly used implementation of this technique in software is the design pattern called Model/View/Controller (MVC).
That's all well and good, but you're probably wondering how this relates to the Swing user interface components in the Java Foundation Classes (JFC). Well, I'll tell you.
While the MVC design pattern is typically used for constructing entire user interfaces, the designers of the JFC used it as the basis for each individual Swing user interface component. Each user interface component (whether a table, button, or scrollbar) has a model, a view, and a controller. Furthermore, the model, view, and controller pieces can change, even while the component is in use. The result is a user interface toolkit of almost unmatched flexibility.
Let me show you how it works.
If you are not familiar with the MVC design pattern, I recommend you review "Observer and Observable", one of my earlier articles that discusses this topic in much greater detail and provides the groundwork for this month's column.
As I mentioned a moment ago, the MVC design pattern separates a software component into three distinct pieces: a model, a view, and a controller.
Figure 1. MVC design pattern
The model is the piece that represents the state and low-level behavior of the component. It manages the state and conducts all transformations on that state. The model has no specific knowledge of either its controllers or its views. The system itself maintains links between model and views and notifies the views when the model changes state.
The view is the piece that manages the visual display of the state represented by the model. A model can have more than one view, but that is typically not the case in the Swing set.
The controller is the piece that manages user interaction with the model. It provides the mechanism by which changes are made to the state of the model.
Using the keyboard key example, the model corresponds to the key's mechanism, and the view and controller correspond to the key's façade.
The following figure illustrates how to break a JFC user interface component into a model, view, and controller. Note that the view and controller are combined into one piece, a common adaptation of the basic MVC pattern. They form the user interface for the component.
java.io package -- class Reader and class Writer -- to filter out unwanted e-mail.