I have a JButton with a .PNG icon on it. I want to get that button click in actionPerformed Method but Jbutton have no Label... Please tell me how i will know that which button clicked?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I have a JButton with a .PNG icon on it. I want to get that button click in actionPerformed Method but Jbutton have no Label... Please tell me how i will know that which button clicked?
Either compare it to the value returned from ActionEvent.getSource(), or only add the ActionListener to that particular JButton so you always know which JButton it was.
If you can't get one of those approaches working, post an MCVE and we'll go from there.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
I have Added ActionListner to it and object is Catch by ActionEvent Parameter in actionPerformed but im a beginner and dont know how to know which button is in ActionEvent Parameter, I always access button by label i.e e.getActionCommand(); but this time i have no label on button i want to draw a rectanle by paint method when button clicked, thats why i want to catch button in actionPerformed
Either compare it to the value returned from ActionEvent.getSource(), or only add the ActionListener to that particular JButton so you always know which JButton it was.
If you can't get one of those approaches working, post an MCVE and we'll go from there.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!