class Timer

I don't know why this code doesn't work:Timer t = new Timer(500, new TimerAction());t.start();The error is: Invalid method declaration.TimerAction is class which implements ActionListenerPlease help me!
[247 byte] By [iliailiaa] at [2007-9-29 13:27:14]
# 1

1 which Timer are you using java.util.Timer or javax.swing.Timer?

java.util.Timer Constructors are Timer() or Timer(boolean isDaemon) and you must schedule them. See the API.

http://java.sun.com/j2se/1.4.1/docs/api/java/util/Timer.html

javax.swing.Timer Constructor is Timer(int delay, ActionListener listener) BUT the ActionListener is really an Action. See the API.

http://java.sun.com/j2se/1.3/docs/api/javax/swing/Timer.html

and look here for an example.

http://java.sun.com/products/jfc/tsc/articles/timer/

benc3a at 2007-7-15 3:43:43 > top of Java-index,Other Topics,Algorithms...
# 2
javax.swing.Timer
iliailiaa at 2007-7-15 3:43:43 > top of Java-index,Other Topics,Algorithms...
# 3

what benc was trying to point out is that you may need to fully qualify the Timer. If you imported the util package, the Timer in your program may be trying to use that instead. So use javax.swing.Timer t = new javax.swing.Timer(500, new TimerAction());

jboeinga at 2007-7-15 3:43:43 > top of Java-index,Other Topics,Algorithms...