Awesome, I got it working, but could you explain this piece of code to me?:
Code:
try
{
Thread.sleep(10000);
}
catch (Exception e) {}
I was using the test.stop() just to play with the timer functions. If I take it out, it still won't work. So I guess my question is, why won't it work (display "test" every second) just like this:
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() );
}
}
The timer appears to be running, it just won't fire the action without that try/catch piece of code. Can anyone explain this to me? Thanks!