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
|
public class Test extends javax.swing.JButton{
private Timer timer;
public Test(){
// Création et lancement du timer
timer = createTimer();
timer.start ();
}
public static void main(String arg[]){
new Test();
}
// Méthode renvoyant un timer prêt à démarrer
private Timer createTimer()
{
// Création d'une instance de listener
// associée au timer
ActionListener action = new ActionListener ()
{
// Méthode appelée à chaque tic du timer
public void actionPerformed (ActionEvent event)
{
System.out.println("Présent !!");
}
};
this.addActionListener(action);
// Création d'un timer qui génère un tic
// chaque 500 millième de seconde
return new Timer (500, action);
}
} |
Partager