• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

#Actualmedv4380

Posted 18 January 2012 - 05:37 PM

Actually, there are two Timer classes in the JDK. You and him are using two different classes. The code the OP isusing is correct for the Timer class he is using. With that said, he already posted this in another thread in this forum, at which I answered his question.

No he is not using his Timer class correctly, and he should read the Java Doc.
He imported
import java.util.Timer;

this the one he is using.
http://docs.oracle.c...util/Timer.html
He cannot use it in that way.

You are thinking of javax.swing.Timer which he might want to use but is not using.
http://docs.oracle.c...wing/Timer.html

He will get a compile error with his code because of an Invalid Constructor call.

You did not need the unnecessary sub class. but if you did want to use it then you should have put this in the Timer constructor:

time = new Timer(5,new TimerListener());

putting the this keyword means that nothing will be rendered due to the fact that in your actionPerformed method in the Board class was empty.

Hope it helped

Gen.

You should actually avoid using 'this' in constructors because it is one of the conditions that can cause Java to leak because it's not fully initialized so it is best to get out of that bad habit. A subclass is a good way to avoid it, but a Factory is better but well beyond what he's doing. However, you're right he used the subclass incorrectly.

#1medv4380

Posted 18 January 2012 - 05:36 PM

Actually, there are two Timer classes in the JDK. You and him are using two different classes. The code the OP isusing is correct for the Timer class he is using. With that said, he already posted this in another thread in this forum, at which I answered his question.

No he is not using his Timer class correctly, and he should read the Java Doc.
He imported
import java.util.Timer;

is the one he is using.
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Timer.html
He cannot use it in that way.

You are thinking of javax.swing.Timer which he might want to use but is not using.
http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html

He will get a compile error with his code because of an Invalid Constructor call.

You did not need the unnecessary sub class. but if you did want to use it then you should have put this in the Timer constructor:

time = new Timer(5,new TimerListener());

putting the this keyword means that nothing will be rendered due to the fact that in your actionPerformed method in the Board class was empty.

Hope it helped

Gen.

You should actually avoid using 'this' in constructors because it is one of the conditions that can cause Java to leak because it's not fully initialized so it is best to get out of that bad habit. A subclass is a good way to avoid it, but a Factory is better but well beyond what he's doing. However, you're right he used the subclass incorrectly.

PARTNERS