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
| nb_th=1;
runner[1] = new Thread(c);
runner[1].start();
}
public void run()
{
if (nb_th==5)
{
try {
runner[nb_th].sleep(nb_th*1000);
}
catch (InterruptedException ex) {}
System.out.println("je dort");
}
else
{
System.out.println("je suis le processus n "+ nb_th);
create_ant();
nb_th++;
try {
runner[nb_th].sleep(nb_th*1000);
}
catch (InterruptedException ex) {}
runner[nb_th] = new Thread (c);
runner[nb_th].start();
}
}
void create_ant(){
a[nb_th] = new ant();
grille2[3][nb_th].add(a[nb_th]);
newContentPane.repaint();
} |
Partager