Trovo che potesse essere fatta in modo più semplice anche senza seguire quell'esempio... la mia versione:
codice:
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Icon;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.JLabel;
class Demo extends JFrame implements ActionListener {
private Timer timer;
private JLabel label, label2;
private int iconIndex = 0;
private Icon icons[][] = {
{ UIManager.getIcon("OptionPane.informationIcon"), UIManager.getIcon("OptionPane.errorIcon") },
{ UIManager.getIcon("OptionPane.warningIcon"), UIManager.getIcon("OptionPane.informationIcon") }
// qui puoi aggiungere altre coppie di icone
};
public Demo() {
label = new JLabel(icons[iconIndex][0]);
label2 = new JLabel(icons[iconIndex][1]);
add(label);
add(label2);
getContentPane().setBackground(Color.BLACK);
setLayout(new FlowLayout());
setSize(600, 400);
// creo timer
timer = new Timer(2000, this);
timer.restart();
}
public void actionPerformed(ActionEvent e) {
iconIndex = iconIndex + 1 >= icons.length ? 0 : iconIndex + 1;
label.setIcon(icons[iconIndex][0]);
label2.setIcon(icons[iconIndex][1]);
}
public static void main(String args[]) {
new Demo().setVisible(true);
}
}