|
| |
The Model-View-Controller Architecture
Swing has adopted the (highly successful) Model-View-Controller (MVC) architecture.
MVC is a commonly-used pattern for Graphical User Interfaces:
- Each component has three characteristics:
- its contents, or state.
- its visual appearance
- its behavior (reaction to events)
- These characteristics are represented by:
- The model, which stores the contents/state, and has no user
interface
- The view, which displays the contents; there can
be more than one view for a model.
- The controller, which handles user input.
Model-View-Controller Interactions

Example
For example, take a very simple component, a button:
- The model stores the content:
- Whether the button is currently pushed in or out, active or
inactive, etc.
- The text to be displayed (if any)
- The view displays the representation of that content:
- The visual indication of the button's state (in or out, active,
etc.)
- The text (if any), clipped if doesn't fit within the confines of the
visual representation.
- The controller handles the user input events:
and translates them into any appropriate changes in the model and/or
view.
|