Author |
Message |
Jonny Tight Lips
|
Posted: Thu Sep 29, 2005 8:26 am Post subject: Clearing the console screen? |
|
|
Just wondering if it is pssoble to clear the console screen kind like cls in turing. Any help would be great. Thx |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Thu Sep 29, 2005 11:28 am Post subject: (No subject) |
|
|
No, it's not.
Turing doesn't have a console screen.
You don't want to clear the screen anyway. The user knows what he or she typed. Wiping it out only serves to make the program more difficult to use.
If you want something like a piece of text centered on the screen, with whitespace all around, in Java you can either use Swing or SWT. |
|
|
|
|
|
1of42
|
Posted: Fri Sep 30, 2005 6:18 pm Post subject: (No subject) |
|
|
wtd is incorrect - on Windows:
will clear the console screen.
using system calls is bad practice, and will make your program non-portable, but it IS possible to do. |
|
|
|
|
|
wtd
|
Posted: Fri Sep 30, 2005 6:30 pm Post subject: (No subject) |
|
|
The language in question is Java. The quickets way to do this in Java would be:
code: | Runtime.getRuntime().exec("cls"); |
|
|
|
|
|
|
[Gandalf]
|
Posted: Fri Sep 30, 2005 7:30 pm Post subject: (No subject) |
|
|
Would that be portable, or not? |
|
|
|
|
|
wtd
|
Posted: Fri Sep 30, 2005 7:39 pm Post subject: (No subject) |
|
|
[Gandalf] wrote: Would that be portable, or not?
It would not.
It would require that the underlying system understand "cls". |
|
|
|
|
|
1of42
|
Posted: Fri Sep 30, 2005 9:40 pm Post subject: (No subject) |
|
|
Well, so wtd, I'm still right - it's not my fault that I thought this was C++ (i'm tired)! I swear! |
|
|
|
|
|
wtd
|
Posted: Fri Sep 30, 2005 9:44 pm Post subject: (No subject) |
|
|
Yes, unfortunately you're right. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Hikaru79
|
Posted: Fri Sep 30, 2005 11:40 pm Post subject: (No subject) |
|
|
Of course, if you're REALLY desperate to do this, and want it to be relatively portable, there's always something like this: Java: | import java.io.*;
public class Test{
public static void main (String [] args){
System.out.println("Hello, world!");
try {
if (System.getProperty("os.name").indexOf("Windows")!=-1){
Runtime.getRuntime().exec("cls");
} else if (System.getProperty("os.name").indexOf("x")!=-1){
String clear_str;
Process clear_proc = Runtime.getRuntime().exec("/usr/bin/clear");
BufferedReader clear_in = new BufferedReader (new InputStreamReader(clear_proc.getInputStream()));
while ((clear_str = clear_in.readLine()) != null) {
System.out.println(clear_str);
}
}
} catch (IOException f){ System.out.println(System.getProperty("os.name")); }
}
} |
This is far from perfect, but it might be enough for some purposes. |
|
|
|
|
|
wtd
|
Posted: Fri Sep 30, 2005 11:43 pm Post subject: (No subject) |
|
|
Should possibly be:
|
|
|
|
|
|
|