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

Username:   Password: 
 RegisterRegister   
 How do I create a delay in java?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Heybob




PostPosted: Mon Mar 20, 2006 10:23 am   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Mar 20, 2006 10:29 am   Post subject: (No subject)

I think you might be looking for sleep()
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
xtreemboarder




PostPosted: Fri Apr 21, 2006 12:47 pm   Post subject: (No subject)

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.


The Extension 'class' was deactivated by an board admin, therefore this Attachment is not displayed.

xHoly-Divinity




PostPosted: Wed Apr 26, 2006 4:10 pm   Post subject: (No subject)

Our teacher taught us to use a useless for loop that runs like a million times Confused . I guess that works as well Twisted Evil
HellblazerX




PostPosted: Wed Apr 26, 2006 8:37 pm   Post subject: (No subject)

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]




PostPosted: Thu Apr 27, 2006 12:49 am   Post subject: (No subject)

xHoly-Divinity wrote:
Our teacher taught us to use a useless for loop that runs like a million times Confused . I guess that works as well Twisted Evil

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




PostPosted: Thu Apr 27, 2006 8:48 am   Post subject: (No subject)

code:
public static void delay (int millisecs)
    {
        try
        {
            Thread.currentThread ().sleep (millisecs);
        }
        catch (InterruptedException e)
        {
        }
    }
[Gandalf]




PostPosted: Fri Apr 28, 2006 2:08 am   Post subject: (No subject)

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.
Sponsor
Sponsor
Sponsor
sponsor
Martin




PostPosted: Fri Apr 28, 2006 3:49 am   Post subject: (No subject)

code:
void delay_a_bit() {
  for (int i=0;i<1000000;++i) {
    int x = Math.sqrt (i * i);
  }
}
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: