Thread: Java Timer
View Single Post
Old 12-09-2004, 10:43 AM   PM User | #2
shmoove
Regular Coder

 
Join Date: Dec 2003
Posts: 367
Thanks: 0
Thanked 0 Times in 0 Posts
shmoove is an unknown quantity at this point
Well, you're starting the Timer, but you're stopping it immediately after that. Try waiting a bit before you stop the Timer:
Code:
  test.start();

   System.out.println( test.isRunning() );
   System.out.println( test.getDelay() );

   // wait 10 seconds before going on.   
   try {
      Thread.sleep(10000);
   }
   catch (Exception e) {}

   test.stop();
You see, the code in the main thread is independent from the Timer, it runs on a different thread. So the main method just continues on after you start the Timer and immediately stops it, before one second passes and the event is fired for the first time.

shmoove
shmoove is offline   Reply With Quote