Is there a way to do a sleep or pause like in C++? Also, running with a text print line in a dos window, is there a way to clear the screen (cls) like in C++? Thanks.....
long secs = 1000 * 10; // 10 seconds as milliseconds
try{Thread.sleep(secs);}catch(InterruptedException ie){}
Pause.. Hmm what do you mean? Pause until any key is pressed? Not sure I know that off the top of my head. The standard keyboard input technique waits for the return key to be pressed before un blocking the read method.
Hit return to continue is easy...
System.out.println("Hit return to continue."
new InputStreamReader(System.in).read();
As for cls, well you can use the Runtime.getRuntime().exec("cls" call, but that produces an expection on my 'XP' machine. This is because cls is a DOS command, not an executable. Someone else might be able to help though..
That is why the intercepted console is useful, because it doesn't depend on the platform.
Pedro Andrés Solorzano
Pontificia Universidad Javeriana
Bogotá, Colombia, SurAmérica.
>> It's just a shame people want to produce DOS programs
>> with Java ! Where's the portability ?
I write command line Java applications all the time. Most of them are Server applications like socket servers etc., although many unit test type applications as well. Actually many classes that i have developed have a static void main() method for the purpose of unit testing. This is of course completely appropriate for this sort of application.
That said, I totaly agree with your point. As soon as a need arose to start wondering how to control the console screen that would be the end of the console interface. We would move to a awt/swing or whatever windowed interface of some kind even if it was a simple dialog.
"But, that's just my opinion... I could be wrong."
-pete
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.