I have to change the the icon of a jLabel every 2 seconds. I use a Timer and a Timer task to do this, but it only shows the first image. Here is the code:
ImageIcon[] icons = {new ImageIcon(this.getClass().getResource("orange.jpg")), new
ImageIcon(this.getClass().getResource("cosmote.jpg")), new
ImageIcon(this.getClass().getResource("vodafone.jpg"))};
java.util.Timer timer = new java.util.Timer();
int indexIcon;
And then in the JFrame constructor:
initComponents();
open(fisierAgenda);
TimerTask task = new TimerTask() {
public void run() {
indexIcon=(indexIcon++)%3;
jLabel.setIcon(icons[indexIcon]);
jLabel.setText(""+indexIcon);
}
};
timer.schedule(task, 0, 2000);
Any help would be much appreciated.