1 import java.util.Timer;
2 import java.util.TimerTask;
3
4 public class TestTimer {
5
6 public static void main(String args[]){
7 System.out.println("About to schedule task.");
8 new Reminder(3);
9 System.out.println("Task scheduled.");
10 }
11
12 public static class Reminder{
13 Timer timer;
14
15 public Reminder(int sec){
16 timer = new Timer();
17 timer.schedule(new TimerTask(){
18 public void run(){
19 System.out.println("Time's up!");
20 timer.cancel();
21 }
22 }, sec*1000);
23 }
24 }
25 }
2 import java.util.TimerTask;
3
4 public class TestTimer {
5
6 public static void main(String args[]){
7 System.out.println("About to schedule task.");
8 new Reminder(3);
9 System.out.println("Task scheduled.");
10 }
11
12 public static class Reminder{
13 Timer timer;
14
15 public Reminder(int sec){
16 timer = new Timer();
17 timer.schedule(new TimerTask(){
18 public void run(){
19 System.out.println("Time's up!");
20 timer.cancel();
21 }
22 }, sec*1000);
23 }
24 }
25 }