I have two JButtons called “Left” and “Right”.
The “Left” button moves a rectangle object to the left and the “Right” button moves it to the right.
I have one ActionListener in the class that acts as the listener for when either button is clicked.
However I want different actions to happen when each are clicked. How can I distinguish, in the ActionListener, between which was clicked?
I have two JButtons called Left and Right. The Left button moves a rectangle
Share
Set actionCommand to each of the button.
// Set the action commands to both the buttons.
UPDATE: