I am trying to make a game in java, when a button is pressed I want it to change icon to indicate that button has been selected, then when it is clicked again I want to change it to its original icon to show it has been deselected.
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b[7][4] && selected == false)
{
b[7][4].setIcon(selected);
selected = true;
}
if(e.getSource() == b[7][4] && selected == true)
{
b[7][4].setIcon(king);
selected = false;
}
}
This code currently does as I wish but it runs both at the same time thus changes the icon and then immediately changes it back to the original icon. How can I make it so one click changes it to selected
and then the second click changes it back to a king
icon?
Aucun commentaire:
Enregistrer un commentaire