Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Delaying
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JSBN




PostPosted: Fri Jun 13, 2003 9:34 pm   Post subject: Delaying

Uh... how do you do a delay in java?
ie: in turing
code:
delay(100)
Sponsor
Sponsor
Sponsor
sponsor
octopi




PostPosted: Fri Jun 13, 2003 11:54 pm   Post subject: (No subject)

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




PostPosted: Sat Jun 14, 2003 10:24 am   Post subject: (No subject)

i tried it but it just screws up my program :/
Thx for trying tho
Tony




PostPosted: Sat Jun 14, 2003 11:45 am   Post subject: (No subject)

You could just run a huge forloop calculating garbage values to waste time Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rizzix




PostPosted: Wed Jun 18, 2003 11:20 pm   Post subject: (No subject)

JSBN wrote:
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..

code:

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




PostPosted: Wed Jul 23, 2003 10:46 pm   Post subject: 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




PostPosted: Thu Jul 24, 2003 3:05 pm   Post subject: (No subject)

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:

code:

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




PostPosted: Thu Jul 24, 2003 8:52 pm   Post subject: delaying

hmmm ... alrite ill try ...

btw ..... this is probably a stupid q ... but wat does

code:
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
Sponsor
Sponsor
Sponsor
sponsor
SilverSprite




PostPosted: Thu Jul 24, 2003 10:05 pm   Post subject: (No subject)

Look in the tutorial section.. there is a tutorial on exception handling.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: