
-----------------------------------
JSBN
Fri Jun 13, 2003 9:34 pm

Delaying
-----------------------------------
Uh... how do you do a delay in java?
ie: in turing
delay(100)

-----------------------------------
octopi
Fri Jun 13, 2003 11:54 pm


-----------------------------------
I have no idea about java, or if this will even make sense to you, but a simple search on google spit out this

Thread.sleep(DELAY);

Where DELAY is a number, any number in milliseconds (I think)


http://www.google.com

-----------------------------------
JSBN
Sat Jun 14, 2003 10:24 am


-----------------------------------
i tried it but it just screws up my program :/
Thx for trying tho

-----------------------------------
Tony
Sat Jun 14, 2003 11:45 am


-----------------------------------
You could just run a huge forloop calculating garbage values to waste time  :lol:

-----------------------------------
rizzix
Wed Jun 18, 2003 11:20 pm


-----------------------------------
i tried it but it just screws up my program :/
Thx for trying tho

hey dude!
That is the way to do it.
You see the only problem it does not work is cuz u haven't caught the exception that is thrown by the static method sleep of the class Thread.

all you have to do is modify ur code to something like this..


try {
    bla;
    bla;
    Thread.sleep(100);
} catch (InterruptedException e) {
    System.out.println(e);
}


basically make sure the Thread.sleep(int msec); is in the try block and that there is a following catch block to catch the InterruptedException exception. ^^

I'll have a tutorial on why we have this funny syntax in Java soon after my exams. You'll see this try/catch/final exception handling used extensively in Java. It's something u need to know.

I'm planning on comming out with more tutorials to explain these concepts and more..

-----------------------------------
poseidon
Wed Jul 23, 2003 10:46 pm

random numbers
-----------------------------------
Is there possibly another way to delay without using try/catch and all that exception stuff?

dam .... doing java makes u appreciate the simplicity of turing .... one liners in turing are replaced w/ these long and complicated lines of bull in java.

-----------------------------------
rizzix
Thu Jul 24, 2003 3:05 pm


-----------------------------------
Turing isn't multi threaded.. Java on the other hand is.. Your application runs in the main thread.. form this thread u can create new threads..

since your application is a thread, it has to trap this interrupt exception. 


if ur sure ur not going spawn new threads ur self then u can try this:


public static void sleep(int msec) {
    try { 
Â  Â      Thread.sleep(msec); 
    } catch (InterruptedException e) { 
Â  Â      System.out.println(e); 
    } 
}


now u can call this method without encapsulating it in a try/catch block. since the method it self handles the exception.

-----------------------------------
poseidon
Thu Jul 24, 2003 8:52 pm

delaying
-----------------------------------
hmmm ... alrite ill try ... 

btw ..... this is probably a stupid q ... but wat does

 catch (InterruptedException e) 

do?

and wat's the purpose of the try/catch commands?

is it used to "catch" or prevent errors or something

btw thx man

-----------------------------------
SilverSprite
Thu Jul 24, 2003 10:05 pm


-----------------------------------
Look in the tutorial section.. there is a tutorial on exception handling.
