Hi,
Please give me an example for MVC pattern used in Java SWING package ?
Hi,
Please give me an example for MVC pattern used in Java SWING package ?
Basically, a Swing component is itself a controller, which has a reference to a view and a model.
The view is in the JComponent.ui
field that is inherited by all swing components and used by the Look&Feel mechanism to provide different visual representations of Swing components.
There are different setModel()
methods in various subclasses that use different model types such as TableModel
or ButtonModel
, which can be implemented by an application programmer to contain the actual data that the Swing UI displays and manipulates.
I have very good experience using Martin Fowler's Presentation Model and its Java Swing implementation.
Look at javax.swing.JTable and javax.swing.table.TableModel. JTable is the View, TableModel is the Model, and the code you write with listeners and events are the Controllers that say when the View needs to be updated.