Results 1 to 2 of 2
Thread: Help with Handler
- 08-04-2007, 09:05 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Help with Handler
Hi, My question is if I have two buttons:
How do I make it so that the add button associates with buttonOne does one thing and the add button associates with buttonTwo does another thing?Java Code:JButton buttonOne = new JButton("ADD"); buttonOne.addActionListener(this); JButton two = new JButton("ADD"); buttonTwo.addActionListener(this);
I have tried the following but both buttons does the same thing when I click on it:
Thanks.Java Code:e.getActionCommand().equals("ADD");
- 08-04-2007, 09:42 PM #2
If you do not explicitly set the actionCommand for a JButton the getActionCommand method will return the button text. This can be a problem when the app is run in a different language. You can avoid this by setting an actionCommand for each button; even if you set the same string as the button text it will be preserved. For your situation you can set different strings for the actionCommand of each button and look for them in the handler.
Java Code:JButton buttonOne = new JButton("ADD"); buttonOne.setActionCommand("unique_string");


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks