change button icon when clicked
ok this is what i need help at.
1.I have 10 images and a grid of buttons(5x5).
2.all the buttons would have image1 as default image on them.
3. when we press any button it should change the icon to image2 and if pressed again it should change the icon to image3 and so on.
4. this has to be implemented on all buttons(5x5).
plz help me by providing the code for this or by advising how it can be done.
thanks in advance
[464 byte] By [
aresh470a] at [2007-11-26 19:34:26]

# 1
> or by advising how it can be done.
read the api docs
most times, if you want to change something it will be in the set...() methods.
you want to change an icon, also look for 'icon' in the method names.
note: many of swing's component methods are inherited - in the case of JButton
look in the api docs section 'methods inherited from AbstractButton'
# 2
1. Put the buttons in an JButton array
2. Put the image in an ImageIcon array
3. Set the actionPerformed for your button, everytime clicked, check the current image number.
4. By then, u can use JButton.setIcon(ImageIcon imageicon) method to change the Icon.
So, duke for me ?