b3ta.com board
You are not logged in. Login or Signup
Home » Messageboard » XXX » Message 4198605 (Thread)

# Does anyone here know anything about


I need to know how to do a delay in java?
e.g. I need the program to do something, wait 2 seconds, then do something else. Anyone able to help out?
(, Wed 26 Jan 2005, 23:47, archived)
# YEah
chew your food longer... maybe
(, Wed 26 Jan 2005, 23:49, archived)
# i haven't programmed java in over a year
but i believe

an easy way to do it would to just make a module with a for loop that does nothing several thousand times and you can call that whenever you need. trial and error, for delay length, i believe. but there has to be a more elegant way to do it.

[edit: you can access the system clock, right? maybe you could do a while loop that stores the first value on the system clock and continues until that has progressed by two seconds. or maybe i'm making stuff up.]
(, Wed 26 Jan 2005, 23:49, archived)
# fyi
(, Wed 26 Jan 2005, 23:50, archived)
# java
(, Wed 26 Jan 2005, 23:55, archived)
# *shudder*
use the sleep();. eg

sleep(1000);

Is 1 second. That currunt thread will then go down had have 40 winks. I read this in my good old Java for Students book a classic with a picture of a mouse on the front.
(, Wed 26 Jan 2005, 23:57, archived)
# thank you
and thanks to kp too.
*goes to try*
(, Thu 27 Jan 2005, 0:04, archived)