I'm wondering about Java GUI panels programming in a good way. My main concern is about methods, panels, labels, listeners, initializing - where?
Where i'm suppose to place these things, how i have to place them between panel and wrapper ( controller too maybe).
Let's say that I have to programm MenuPanel with MenuPanelWrapper containing some buttons and so on. How to do this in a best way?
I think the best way to create some Java UI is to use the MVC (model-view-controleur) pattern.
Let's suppose that: we have a JButton, JLabel and a JTextField in our Java UI, like this :
On the left we have the UI and on the right we have the design of the MVC. In this UI, the user can put some text in the JTextField, and display it in the JLabel by pressing the JButton.
Step 1
Now if the user change the value of the JTextField, this will affect the JtextField of the Controler.
Step 2
If the user press the JButton, the Controler will change the value of the Model.valueLabel by calling the setter of the Model.
Step 3
At this step, the Model will notify his View that the value of the Model.valueLabel has changed. And the View will refresh himself (by changing the value of the JLabel). Finally, the JLabel display the value of the data Model.
Step 4 - In some case
After the View has finished his refresh, he can refresh the Controler by adding or disabling some actions.
P.S: Sometimes the view and the controler are together and it's more like a Model and ViewControler, when we cannot separate the View and the Controler.