Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Clearing the console screen?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jonny Tight Lips




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: 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




PostPosted: Fri Sep 30, 2005 6:18 pm   Post subject: (No subject)

wtd is incorrect - on Windows:

c++:

system ("cls");


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




PostPosted: 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]




PostPosted: Fri Sep 30, 2005 7:30 pm   Post subject: (No subject)

Would that be portable, or not?
wtd




PostPosted: 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




PostPosted: 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! Laughing
wtd




PostPosted: Fri Sep 30, 2005 9:44 pm   Post subject: (No subject)

Yes, unfortunately you're right.
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: 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




PostPosted: Fri Sep 30, 2005 11:43 pm   Post subject: (No subject)

code:
/usr/bin/clear


Should possibly be:

code:
/usr/bin/env clear
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: