Clearing Screen
Author |
Message |
Unnamed.t
|
Posted: Fri May 28, 2010 10:10 pm Post subject: Clearing Screen |
|
|
I am having tremendous problems in clearing the screen for my java programs.
There isn't a command like cls (Turing) or clrscr (C++).
I have tried using Runtime.exec ("cls") and Runtime.exec ("cmd cls") and another type of Runtime method. All of these failed.
I have heard of running the program in windows' ansi.sys folder (something like that)
I wish to seek a way to clear screen without using that.
I only have problems clearing screen with text (graphics is fairly easy (g.fillRect Color.WHITE)). I am currently using System.out.println ("\n\n\n\n\n\n\n\n\n\n\n\n"). I don't want to use that because it looks fairly bad to have my text run at the bottom of the output screen. I can change the screen size so it wouldn't look as bad, but I am still looking for a clear screen command because I may have text with ranging sizes.
Another way to do this is by covering the previous text with the spaces and reoutputting the new text. For this I need to know of a command similar to the locate (row,column) or locatexy (x,y) commands in Turing. For those of you who don't know what these commands do; they output your text at the specified location on the screen.
+ all my bits for anyone who can find a way to clear screen that is very similar to the cls or clrscr commands.
Some additional information is that I want to be able to have this command work in frame application templates and just normal application templates. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Euphoracle
|
Posted: Fri May 28, 2010 11:07 pm Post subject: RE:Clearing Screen |
|
|
Wow did you steal Tony's avatar? Lame.
In related news, Java does not have a proper clear screen 'method' if you will because it doesn't assume ANYTHING about the console. If you want to clear the screen or set the cursor position, you have to use an external library (maybe JCurses or similar). |
|
|
|
|
|
TheGuardian001
|
Posted: Sat May 29, 2010 6:31 am Post subject: Re: Clearing Screen |
|
|
Java will never assume that it has full control over the console, since it doesn't technically have its own console. Console apps are generally meant to be run from whatever command line interface is available in a given operating system (comman prompt, terminal, etc), so it doesn't allow clearing in case something else has been run in the same terminal window. |
|
|
|
|
|
DtY
|
Posted: Sat May 29, 2010 10:50 am Post subject: RE:Clearing Screen |
|
|
I am assuming here you are writing a text based application?
All you can do with text based programs is output text and input text, however (and change some options, like turning noecho on), there is a "standard" way to tell the terminal to do stuff like move the output location, clear the screen, even change the colour. These are called Ansi escape sequences (American National Standards Association), nearly every software terminal supports them (xterm, Terminal.app, gnome-terminal...), the windows terminal doesn't, at least not by default, see ANSI.SYS for windows/dos. Alternatively, you could install cygwin and use xterm, but that's more involved.
Now, to use Ansi escape sequences, all you have to do is output the right text. All the sequences start with "\uoo1B[", and then the code to do that action.
See https://secure.wikimedia.org/wikipedia/en/wiki/ANSI_escape_code |
|
|
|
|
|
Unnamed.t
|
Posted: Sat May 29, 2010 10:54 am Post subject: Re: Clearing Screen |
|
|
Alright that makes sense. Thanks for the explanation both of you, but I'm still interested in the command that is similar to the locate command in Turing. I'm pretty sure that there should be a command like that.
Euphoracle wrote: Wow did you steal Tony's avatar? Lame.
Well yes i kinda did steal it ... but It just goes to show how much I look up to Tony (and Dan of course) |
|
|
|
|
|
Unnamed.t
|
Posted: Sat May 29, 2010 11:00 am Post subject: Re: Clearing Screen |
|
|
Thank you for the link DtY. I have heard of the ansi.sys escape commands. I guess that will have to do ... I was just hoping that clearing screen could be just as easy as C++. O well this just gives me another reason not to use Java (im still gonna use it anyways)
And to answer your question, yes I am writing a text based application. |
|
|
|
|
|
DtY
|
Posted: Sat May 29, 2010 11:19 am Post subject: Re: Clearing Screen |
|
|
Unnamed.t @ Sat May 29, 2010 11:00 am wrote: Thank you for the link DtY. I have heard of the ansi.sys escape commands. I guess that will have to do ... I was just hoping that clearing screen could be just as easy as C++. O well this just gives me another reason not to use Java (im still gonna use it anyways)
And to answer your question, yes I am writing a text based application. you can wrap it into a function;
code: | void cls() {
system.out.print("\u001B[2j");
} |
|
|
|
|
|
|
Unnamed.t
|
Posted: Sat May 29, 2010 1:06 pm Post subject: Re: Clearing Screen |
|
|
DtY wrote: you can wrap it into a function; code: |
void cls() {
system.out.print("\u001B[2j");
} |
Yupp that is what I was planning to do. Have a method that redisplays the title of the program and clears the screen. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|