Using the MVC Model with the Swing Application Framework

I am trying to create a simple Java desktop application using the Swing Application Framework and the MVC model, but I am struggling with some areas because there is a lack of good examples (the only SAF examples I found are nothing but MVC!).

I manage to fire events from components, but besides this I try to use the MVC model with SAF. Are there any examples anywhere?

For example, I fire an event (associated with @Action) in a viewer that sends it to the controller. But what function should I use? My AbstractController extends the PropertyChangeListener property.

How do I bind with SAF to both directions (model -> controller and view -> controller)?

+4
source share
1 answer

I can recommend this article: Overview of Swing Architecture .

In the example, when using JTable (view), you create a model by extending AbstractTableModel and handling custom events with Actions and listeners.

The user can write some text in the JTextField, and you bind the action to the "Add" -JButton. In Action Action actionPerformed (), you can call the Add-method on the model to add text. In the Add-method, you save the data and then call fireTableRowsInserted (), and the view will be updated.

Swing components often contain a default model and view.

EDIT: Sorry, did not know about Swing Application Framework. My answer was directed only to Swing.

+3
source

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