10 seconds countdown on console
I wrote this program for a simple count down program. It compiles but nothing happens. Where have i gone wrong. I've never used Timers before:
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class timer implements ActionListener{
Timer t;
private int countdownPeriod = 0;
private final int ONE_SECOND = 1000;
private void write()
{
System.out.printf("%s, ", this.countdownPeriod);
}
public timer(int seconds)
{
this.countdownPeriod=seconds;
t = new Timer(this.ONE_SECOND,this);
t.setInitialDelay(0);
t.start();
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(this.countdownPeriod==0)
{
t.stop();
}else{
this.countdownPeriod--;
write();
}
}
public static void main(String args[])
{
timer tom = new timer(10);
}
}