Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dos window question

Status
Not open for further replies.

youdaman

Technical User
Dec 26, 2001
66
0
0
US
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.....
 
Sleep is easy (ish)

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..



 
As for the clear screen method, check this thread (answer at the end).

thread269-431589

Hope it helps. Pedro Andrés Solorzano
Pontificia Universidad Javeriana
Bogotá, Colombia, SurAmérica.
 
So, the answer is "no you can't cls the DOS shell" You have to implement your own Console class if you want that functionality.

Am I correct Pedro?
 
Hi thekobbler:

Yes, thats right. Why, you didn't like it?

At least for what I know, this is the only way. As the JTextArea will reproduce the behavior of the dos shell it will have no apparently difference.

Dont you think?
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 ?
 
Hi thekobbler:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top