Temporisation d'un affichage
Bonjour,
Le "tac" ne s'affiche pas, pouvez-vous me dire pourquoi svp !
Code:
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
| import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class test2 {
test2() {
int i;
System.out.println("lancement du timer");
Timer timer;
for (i = 0; i < 5; i++) {
// Création et lancement du timer
timer = tempo();
timer.start();
System.out.println("boucle = " + i);
}
}
// Méthode renvoyant un timer prêt à démarrer
public Timer tempo() {
// Création d'une instance de listener associée au timer
ActionListener action = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("tac");
}
};
System.out.println("tic...");
// le timer génère un top chaque 1000 millième de seconde
return new Timer(1000, action);
}
public static void main(String[] args) {
System.out.println("main");
test2 t = new test2();
}
} |