I have two buttons in my project that both have a \"+\" label. When the actionPerformed() method is called, it calls a specific method based on the label. How can I distigui
Use ActionEvent#getSource
Set the actionCommand
property of each button to something unique and use ActionEvent#getActionCommand
Use separate listeners, either anonymously or as inner or outer classes depending on your needs
Make use of the Action
API, which would allow you to define a common/abstract Action
which defined the common properties (like the +
text) and then extend this to make unique actions for each button
See How to Use Actions for more details
Use JButton#putClientProperty
to set some unique flag on each button and cast the ActionEvent
to a JComponent
and use getClientProperty
to retrieve the flag ... but given the previous suggestions, I'm not sure why you'd bother