Reputation: 21
I want to change the icon on a button based on what i clicked. The issue is i have an array and it is shuffled so i need a way of changing the icon based on what one of my 30 buttons i clicked.
For example something like this
if (source == "dos")
{
change my icon on what button i clicked to this (icon)
}
Upvotes: 0
Views: 190
Reputation: 324157
i need a way of changing the icon based on what one of my 30 buttons i clicked.
You get the button that was clicked from the ActionEvent
of your ActionListener
:
JButton button = (JButton)event.getSource();
button.setIcon(...);
Upvotes: 1