MVC pattern in Java Swing?

Please give me an example for the MVC pattern used in the Java SWING package?

+3
source share
3 answers

Basically, the Swing component itself is a controller that has a reference to the view and model.

The view is in a field JComponent.uithat is inherited by all swing components and is used by the Look & Feel mechanism to provide various visual representations of the Swing components.

Different subclasses have different methods setModel()that use different types of models, such as TableModelor ButtonModel, which can be implemented by a programmer to contain actual data displayed and controlled by the Swing user interface.

+6
source

Take a look at javax.swing.JTable and javax.swing.table.TableModel. JTable is View, TableModel is the model, and the code you write with listeners and events are controllers that say when the View needs to be updated.

+4
source

Martin Fowler Java Swing.

+2

Source: https://habr.com/ru/post/1738770/


All Articles