1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| public class SwingUti extends JFrame{
////// declaration de ce qu'on a besoin
public JLabel titre;
public JFormattedTextField reponse;
///////////////////////////////////////////////////////////////////
public class SwingUtiWorker extends SwingWorker<Integer,Integer> {
public int valeur;
public int valeur_min = 0;
public int valeur_max = 999;
public SwingUtiWorker(){
}
@Override
public Integer doInBackground(){ // la variable valeur prend une valeur aléatoire 100x
try {
Thread.sleep(500);
} catch(InterruptedException e) {
e.printStackTrace();
}
for(int i=0;i<1000;i++){
Random r = new Random();
valeur = valeur_min + r.nextInt(valeur_max-valeur_min);
reponse.setValue(valeur); //---> ICI
// System.out.println(valeur);
}
return valeur;
}
@Override
protected void done(){
System.out.println("traitement terminé");
System.out.println(valeur);
}
}
public SwingUti(){
// construction de l'interface
}
} |
Partager