Hi im trying to get this super simple counter to work on a 1 second delay. But for some reason i can't for the life of me get it to update the counter.
Code:
import java.util.Timer;
import java.util.TimerTask;
/**
* Schedule a task that executes once every second.
*/
public class Clock {
Timer timer;
public Clock() {
timer = new Timer();
timer.schedule(new RemindTask(), 0, //initial delay
1 * 1000); //subsequent rate
}
class RemindTask extends TimerTask {
int num = 3600; //one hour
public void run() {
if (num > 0) {
int count = 0;
System.out.println("The number of seconds passed = " + (count = count + 1));
num--;
}
else {
System.out.println("Time's up!");
System.exit(0); //Stops the AWT thread (and everything else)
}
}
}
public static void main(String args[]) {
System.out.println("About to schedule task.");
new Clock();
System.out.println("Task scheduled.");
}
}