Java Swing: separating UI component from logical behavior - how do you approach this?

What am I doing in NetBeans, for example:

  • create a class of user interface components with a Swing type suffix, for example. JPanel, for example. MyUIWidgetJPanel
  • create a logic / behavior class to handle behavior / logic, i.e. what happens when a user interface component is used, for example. buttons inside it, etc., MyUIWidgetLogic

I can also link components / logic together using links if the behavior / result of one component affects / affects another, for example. some displayed parameters are no longer relevant or provide context-sensitive parameters.

What do you think about this? Good? Poorly?

What do you do?

+3
source share
4 answers

I usually use the View Model Model .

Essentially, it looks like you are doing: create a class that includes logic separate for the user interface class. User interface classes should not contain logic - only the code needed to display the interface.

Then you can bind your interface values ​​to the base class of presentation presentations using something like JGoodies Binding (I understand that Spring RCP is good for that too).

+5
source

Swing, UI.

Filthy Rich Chet Haase Romain Guy .

+4

Swing Thread Dispatch Thread, , , ActionListener (, JButton). ActionListener , , , (, JButton) , ActionListener .

+2

, , MVC (Model View Controller) , . , , () (), , . MVC , , ( ).

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

+1

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


All Articles