Ciao a tutti,
premesso che sono alle prime armi nella programmazione java, volevo chiedere aiuto sul mio problema.
Devo fare un amtrice di bottoni nella quale ogni bottone è associato alla stessa immagine .gif e fin qui tutto ok, il problema sorge quando devo modificare l'icona del bottone cliccandoci sopra perchè voglio aggiungere ad ogni click un icona diversa fino ad un massimo di 4 poi dopodichè vorrei ritornare sempre clickkando sul bottone alla prima icona. Comunque in sostanza in base al numero di click dati dall'utente l'immagine è quella associata al numero di click che potrebbe anche essere un numero elevato nonostante le sole 4 icone che voglio aggiungere.
spero di essermi spiegato cmq allego qui sotto il mio codice e spero che qualcuno mi possa aiutare.

package newpackage;

import java.awt.*;
import javax.swing.*;
import java.io.*;

/**
*
* @author Student
*/

public class myform extends javax.swing.JFrame {
JButton[][] buttons = new JButton[5][5];
Integer[][] i = new Integer[5][5];
Integer[][] j = new Integer[5][5];
ImageIcon icon = new ImageIcon("c:/0.gif");
String name=new String();

ImageIcon icon1 = new ImageIcon
("C:/1.gif");
ImageIcon icon2 = new ImageIcon
("C:/2.gif");
ImageIcon icon3 = new ImageIcon
("C:/3.gif");





/** Creates new form NewJFrame */
public myform() {
initComponents();
setTitle("Button");
setBounds(8,8,0,0);


for (int i=1;i<buttons.length;i++){
for (int j=1;j<buttons.length;j++){

buttons[i][j] = new JButton(new ImageIcon ("c:/0.gif"));
this.getContentPane().add(buttons[i][j]);
this.pack();



buttons[i][j].addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JButtonActionPerformed(evt);

}
});


}
}




}


/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {

getContentPane().setLayout(new java.awt.GridLayout(5, 6));

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
pack();
}
// </editor-fold>

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new myform().setVisible(true);
}
});
}

private void JButtonActionPerformed(java.awt.event.ActionEvent evt) {

JButton who = (JButton) evt.getSource();

if (who.equals(who)){
who.setIcon(icon1);

//return a;
}


}


// Variables declaration - do not modify
// End of variables declaration

}