I am trying to separate a function from state in my GUI application using Action objects. I managed to use them to create menu items and buttons that have the same functionality.
My problem is this: I want to have the same action for the "exit" element in my menu and the close frame button.
Currently, I was able to solve this problem by adding the following WindowListener to the frame:
private class MainWindowListener extends WindowAdapter { @Override public void windowClosing(WindowEvent e) { new ExitAction(model).actionPerformed(new ActionEvent(e.getSource(), e.getID(), "Exit")); } }
Is there a simpler and simpler way to do this?
FinalArt2005
source share