Thread: Java Timer
View Single Post
Old 12-09-2004, 09:19 AM   PM User | #1
FalcorTheDog
New to the CF scene

 
Join Date: Dec 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
FalcorTheDog is an unknown quantity at this point
Java Timer

I just started playing with timers today, so I'm not too sure what I'm doing. All I want is to get something simple to work... Here I'm trying to display "test" once every second. Why isn't it working? The timer appears to be running, but the actionevent isn't working. Any ideas?



Code:
import javax.swing.Timer;
import java.awt.event.*;

public class TimerTest
{

   public static void main( String args[] )
   {
   int delay = 1000; //milliseconds
   
   ActionListener taskPerformer = new ActionListener()
      {
      public void actionPerformed(ActionEvent evt)
         {
         System.out.println( "test" );
         }
      };

   Timer test = new Timer(delay, taskPerformer);

   test.start();

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

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

   }

}

Last edited by FalcorTheDog; 12-09-2004 at 09:25 AM..
FalcorTheDog is offline   Reply With Quote