Delay command in Java?

SenorDingDong

Newbie
Joined
May 18, 2003
Messages
382
Reaction score
0
Is there a delay method or anything in Java. Im making a small dice game, and want to change the image (its an ImagIcon in a JLabel) of dice, then stop on one, to look like its rolling, accept i have to slow it down, or else it will change through them all in like .5 seconds.

And no I dont want to just make a for loop that will run a million times, as thats a horrible way to do it.
 
VigilanteP said:
Thread.sleep(long milliseconds)
If you have any other threads running code control will pass to next thread in line, so don't use it if you have multiple threads and don't want the other threads to be invoked when you sleep. I haven't done Java in a very long time though.
 
It might be possible to have the program run with the computer clock, Try a infinate for loop with an if statement. When the clock reaches or passes a previously defined time out side of the loop (which is basicly current time + x miliseconds) it will break out of the for loop.

Think of it like this..

delaytill = [current time (probably parsed to a double or long if its a string)] + [x];
for ( ;; )
{
if ([current time] = delaytill)
{
break;
}
}

//Though.. that probably won't work. Its an idea, though.
 
JellyWorld said:
If you have any other threads running code control will pass to next thread in line, so don't use it if you have multiple threads and don't want the other threads to be invoked when you sleep. I haven't done Java in a very long time though.

Does that really matter? When the thread in question is running other active threads will still be invoked, placing the thread into sleep mode shouldn't have any effect on how the other threads behave.
 
Back
Top