hi there i am trying to make a matching memory game which i use JToggleButton. the main thing is when i press to button it must show a picture and i must find the other same
One approach is to do the following:
Icon.Code outline:
/** Handle ItemEvents. */
@Override
public void itemStateChanged(ItemEvent e) {
GameButton gb = (GameButton) e.getItem();
gb.setState();
}
/** Remove a and b from play. */
private void retirePair(GameButton a, GameButton b) {
a.setSelected(true);
a.setEnabled(false);
b.setSelected(true);
b.setEnabled(false);
}
class GameButton extends JToggleButton {
...
public void setState() {
if (this.isSelected() || !this.isEnabled()) {
this.setIcon(icon);
} else {
this.setIcon(hidden);
}
}
}