Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using JButton i can't check equality in ActionEvent

 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my situation,I created a JButton with only image in it using ImageIcon (which i am using as toolbar button in my application).

Here is the code sample



Now i have to check for the equality condition in actionPerformed method

 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ae.getSource() will return the button or any other source of the event. You will have to check its type and/or cast it, since it returns an Object.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Balu" -

Welcome to the JavaRanch! We don't have many rules around the ranch, but we do have a policy on displayed names... Please adjust your displayed name to meet the JavaRanch Naming Policy. User names cannot be obviously fake and must consist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob i used getSource() method and my problem was solved....

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!