
-----------------------------------
Heybob
Mon Mar 20, 2006 10:23 am

How do I create a delay in java?
-----------------------------------
If I want to delay something in java, how would I do it? I know in turing there is a delay (*) but Im not sure what it is for java.

-----------------------------------
Tony
Mon Mar 20, 2006 10:29 am


-----------------------------------
I think you might be looking for sleep()

-----------------------------------
xtreemboarder
Fri Apr 21, 2006 12:47 pm


-----------------------------------
use this... put it in the same directory as your program... and in your program put "Delay.stop(int);" before whatever you want delayed.... just like in turing.

-----------------------------------
xHoly-Divinity
Wed Apr 26, 2006 4:10 pm


-----------------------------------
Our teacher taught us to use a useless for loop that runs like a million times :? . I guess that works as well :twisted:

-----------------------------------
HellblazerX
Wed Apr 26, 2006 8:37 pm


-----------------------------------
errrr not really, cuz you're delaying by the number of times your CPU can go through that for loop, so the slower comp you have, the longer delay you'll have.

-----------------------------------
[Gandalf]
Thu Apr 27, 2006 12:49 am


-----------------------------------
Our teacher taught us to use a useless for loop that runs like a million times :? . I guess that works as well :twisted:
This is far worse than using processes in Turing, and you know how bad that is.  Unless, of course, you have a constant frame rate, but even then using the Thread.sleep() method is what you should be using.

-----------------------------------
codemage
Thu Apr 27, 2006 8:48 am


-----------------------------------
public static void delay (int millisecs)
    {
        try
        {
            Thread.currentThread ().sleep (millisecs);
        }
        catch (InterruptedException e)
        {
        }
    }

-----------------------------------
[Gandalf]
Fri Apr 28, 2006 2:08 am


-----------------------------------
Note that you don't need to explicitly state that you're delaying currentThread(), Thread.sleep() should be sufficient, especially since you're probably only working with the default Thread.

-----------------------------------
Martin
Fri Apr 28, 2006 3:49 am


-----------------------------------
void delay_a_bit() {
  for (int i=0;i