By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,149 Members | 885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,149 IT Pros & Developers. It's quick & easy.

Clear screen

P: n/a
How would you clearn the screen in a console program???

Thanks
NeoPhreak >.<
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"NeoPhreak" <ad***@neophreak.com> wrote in message
news:vS*******************@news20.bellglobal.com.. .
How would you clearn the screen in a console program???


Console control is not Java's strong point. Generally there are three
approaches to this task:

* Use 'System.out.println' to write out enough space characters to
fill the screen [doesn't, however, provide very effective cursor
control :) !]

* If the console suports ANSI escape sequences, then the
following will do the trick:

final static String ESC = "\033[";
System.out.print(ESC + "2J"); System.out.flush();

* Use a JNI routine that makes the relevant OS system
call to perform this task. You should find these in
console-based libraries - do a search for JCurses or
any other Java-based Curses implementation

I hope this helps.

Anthony Borla

P.S.

Forget about your Java program responding to single keystrokes [i.e. without
the need to press ENTER]. Again, a suitable JNI routine or package like
JCurses is required
Jul 17 '05 #2

P: n/a
On Tue, 11 Nov 2003 16:52:45 -0500, "NeoPhreak" <ad***@neophreak.com>
wrote:
How would you clearn the screen in a console program???

Thanks
NeoPhreak >.<


Depends on the operating system... on Windows 9x and most flavors of
Unix (in a terminal window) you can use:

System.out.println(((char) 27)+"[2J"); // ANSI clear screen...

But NOTHING works in Windows NT. So you can write some JNI code, or
do something silly like:

for (int i=0; i<25; ++i) System.out.println();
Jul 17 '05 #3

P: n/a
Never did find a way to do that ...
cheers

"NeoPhreak" <ad***@neophreak.com> wrote in message
news:vS*******************@news20.bellglobal.com.. .
How would you clearn the screen in a console program???

Thanks
NeoPhreak >.<

Jul 17 '05 #4

P: n/a
http://www.xdweb.net/~dibblego/javafaq/javafaq.html#q30

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
"Denz" <RU*************@RUBBISHhotmail.com> wrote in message
news:tB******************@news-server.bigpond.net.au...
Never did find a way to do that ...
cheers

"NeoPhreak" <ad***@neophreak.com> wrote in message
news:vS*******************@news20.bellglobal.com.. .
How would you clearn the screen in a console program???

Thanks
NeoPhreak >.<


Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.