Adding an actionlistener to a JButton with no text
I'm having trouble figuring this out. I would normally just do something like
Code :
JButton blah = new JButton("blah");
String str = e.getActionCommand();
if(str.equals("blah") {
//do something
}
but now I'm using an icon for the JButton instead of text.
Code :
ImageIcon createIcon = new ImageIcon("images/new.png");
JButton create = new JButton(createIcon);
create.addActionListener(new EventHandler());
what would I do in the eventhandler class?
Re: Adding an actionlistener to a JButton with no text
Presuming 'e' is an ActionEvent from an ActionListener registered with the JButton - use the setActionCommand method of JButton, or compare the source of the event to the Component, or separate out into a single ActionListener to Listen to only that JButton, ...many ways
Edit: and please read the forum rules. Double posting is not allowed. Your other post has been deleted and I have moved this to a more appropriate location