hi
im making a tic-tac-toe game and i want to set a delay of one second between moves from user and computer
i dont know how to use
setDelay(int)
can you give me an example
thanks chris
Printable View
hi
im making a tic-tac-toe game and i want to set a delay of one second between moves from user and computer
i dont know how to use
setDelay(int)
can you give me an example
thanks chris
Thread.sleep() ??????????
i tried
Thread.sleep(1000);
and give me error must be caught
Timer timer = new Timer();
this doesnt work give me an error
C:\Documents and Settings\chris\Desktop\GAMES BY CHRIS\TicTacToe.java:12: cannot resolve symbol
symbol : constructor Timer ()
location: class javax.swing.Timer
Timer timer = new Timer();
^
1 error
please help!!
there is no constructor in javax.swing.Timer that has no parameters, so essentially you're trying to use a method that doesn't exist. Obviously the compiler won't let you do that :) go here to see the api for javax.swing.Timer and it will show you how to use it and what it does.
Thanks for the link
im still haveing trouble using it though
i tried
setDelay(100);
gives me this error
C:\Documents and Settings\chris\Desktop\GAMES BY C HRIS\TicTacToe.java:88: cannot resolve symbol
symbol : method setDelay (int)
location: class TicTacToe
setDelay(10000);
^
1 error
Tool completed with exit code 1
is that thr right way to format it?
Am i missing something??
Baically what i wanted to use the timer for is for stoping the program for one second
the error means that the compiler doesn't recognise the method setDelay(). You need to specify the object that the method belongs to since I assume it's not a method in your class right? Something like someObject.setDelay().
I'm not sure if you understood my last post so i'll clarify it now. You tried to make a Timer object using a constructor with no paramters. The class Timer doesn't have such a constructor, it only has construcors that have parameters in them. The link i gave in the last post goes to the API for Timer and shows how to use it.
ummm....
why not try putting a try/catch around the sleep call.
try
{
Tread.sleet(1000);
}
catch(InterruptedException e){}
That should be all you need to do.
Dave
Tread.sleet? :DQuote:
Originally posted by sirHensley
try
{
Tread.sleet(1000);
}
DOH!!! :o
We definitely dont need any sleet in our java code. How about using sleep instead...and we probably want to use a Thread and not a Tread :).
try
{
Thread.sleep(1000);
}
catch(InterruptedException e){}
I think I need typing lessons.
Dave