i am trying to learn more about event handling but everywhere i read about it, it's mainly about how to use it so something happens but not how it works.
So far i know about 2 ways to make something happen when a button is clicked.
ActionListener:
myButton.addActionListener(new ActionListener() { @override actionPerformed... });
and AbstractAction:
public class MyAction extends AbstractAction {
public MyAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
public void actionPerformed(ActionEvent e) {
System.out.println("Action", e);
}
}
MyAction myAction = new MyAction(...);
myButton.setAction(myAction);
I know that i can write everything i want to happen into the actionPerfomed()
method.
But since i do not know, what exactly happens in the background I can not tell if one has any advantage over the other or which one i should use in which situation?