Click to See Complete Forum and Search --> : Java Pause/Wait/Stall help


Nickyg2006
October 21st, 2004, 11:59 AM
I've googled for about an hour trying to find a tutorial or just some random info on the net on how to make a program wait for "x" seconds before continuing on with the program. I have found one for C++, and even though I know its similar, it just wasn't working.

I was wondering if there was a command like sleep(x); or something that I'm missing. I know threads run concurrently, and I don't want to have to make my code messy. I'm a beginner, and to just jump into coding and learning the basics and advanced basics, I'm trying to program a dos text-based choose-your-own adventure type game.

Any help would be greatly appreciated.

cma
October 21st, 2004, 12:23 PM
If you want your program to pause for a certain amount of time, you can use Thread.sleep() (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#sleep(long))

Example:

// pause current thread for 3 secs
try { Thread.sleep(3000); } catch (InterruptedException exc) {/* code to handle what happens if someone didn't want you to sleep*/}

Nickyg2006
October 22nd, 2004, 10:29 AM
:) Yay. Thanks a bunch.