eccoti un semplice e "rudimentale" mio esempio per il tuo programma(l'ho fatto al volo senza riguardarlo,possono esserci inefficienze o anche errori)
codice:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.Timer;
class Ruota extends JFrame implements ActionListener{
private JLabel l;
private JButton jb;
private Timer t;
public Ruota() throws Exception{
super("Ruota");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
Container c=getContentPane();
l=new JLabel();
jb=new JButton("mischia");
jb.addActionListener(this);
JPanel panel=new JPanel();
panel.setPreferredSize(new Dimension(100,100));
panel.setBackground(Color.ORANGE);
panel.add(l,BorderLayout.CENTER);
l.setHorizontalAlignment(JLabel.CENTER);
c.add(jb,BorderLayout.NORTH);
c.add(panel,BorderLayout.CENTER);
t=new Timer(500,this);
t.start();
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb&&t.getDelay()!=0){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
l.setText(new Random().nextInt(10)+"");
t.setDelay(t.getDelay()-1);
actionPerformed(new ActionEvent(jb,0,null));
System.out.println("delay= "+t.getDelay());
}
});
}else{
t.setDelay(500);
}
}
public static void main (String [] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try{
new Ruota();
}catch(Exception ex){
ex.printStackTrace();
}
}
});
}
}
Ps. invece che un ciclo for con i numeri ordianati ho fatto una generazione di numeri casuali!