samedi 7 mars 2015

Why isn't my timer working?




public class TimerProgram extends JFrame {
public TimerProgram(){

int DELAY=1000;
Timer t = new Timer(DELAY,new TimerListener());
t.start();

}
class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println("Hello");

}
}

public static void main(String[]args){
new TimerProgram();
}
}


I am trying to make a timer that outputs every second the word hello, but it seems that when I type as the DELAY value 1000 , it outputs hello once and then it terminates. What am I doing wrong ? All help appreciated!




Aucun commentaire:

Enregistrer un commentaire