I would like to add components by doing this:
frame.add(new JButton("Click here"));
But how would I add an ActionListener then? I assume it might have to do with AbstractButton instantiation?
I don't want to instantiate a JButton variable, so I'm not sure if this is the proper way to do it:
frame.add(new JButton("Click here"), new AbstractButton() {
public void addActionListener(ActionListener l) {
// do stuff
}
});
If this works, I need it to be added in the actionPerformed() like this:
JButton button = new JButton("Click here");
button.addActionListener(this);
Note, that I'm not trying to do anonymous inner class for the ActionListener, but just a code simplification to add the component to the actionPerformed().
Is there any way to do this?
Thanks