user3020002
user3020002

Reputation: 21

Java Action Listener Change Object From Source

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

Answers (1)

camickr
camickr

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

Related Questions