abstract-action

Java: How to reference GUI components from an AbstractAction object?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 08:08:31
问题 It is often necessary to change the behaviour of other GUI objects depending on the state of another GUI object. E.g. when a button is pressed, a label shall change its name. However, when I use an AbstractAction object like JButton myButton = new JButton(myButtonAction); I need a reference to the GUI objects in the object that inherits from AbstractAction. Should I just create the AbstractAction objects in the GUI and then pass all the necessary GUI references to the AbstractAction objects

How do I organize my Actions in Swing?

半腔热情 提交于 2019-11-28 00:28:46
I am currently replacing my anonymous ActionListeners new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { // ... } } with class files representing actions: public class xxxxxxxAction extends AbstractAction { } However, my GUI is able to perform a lot of actions (eg. CreatePersonAction, RenamePersonAction, DeletePersonAction, SwapPeopleAction, etc.). Is there a good way to organize these classes into some coherent structure? You can keep your actions in a separate package to isolate them. Sometimes, it is useful to keep them in one class, especially if

How do I organize my Actions in Swing?

做~自己de王妃 提交于 2019-11-26 23:25:38
问题 I am currently replacing my anonymous ActionListeners new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { // ... } } with class files representing actions: public class xxxxxxxAction extends AbstractAction { } However, my GUI is able to perform a lot of actions (eg. CreatePersonAction, RenamePersonAction, DeletePersonAction, SwapPeopleAction, etc.). Is there a good way to organize these classes into some coherent structure? 回答1: You can keep your actions in