Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to clean the screen?  RSS feed

 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone tell me how to clean the screen? I mean like in Pascal CLRSCR(). To be honest I have no idea.

Thanks in advanced.

Enrique Villamizar
 
Richard Anderson
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused.....

Do you want to do this from within a Java class? On the command line?
 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to do it within a Java Class. For example, for doing a Menu. I need to clean old data and show new information on the screen (console). Do you understand what I mean?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java has no built-in cursor-control features. You have two choices: one is to send ANSI escape sequences, which will work on ANSI terminals (i.e., vt100 emulators) only. The other choice is to clear the screen by printing a bunch of blank lines.
 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest for your fast answer. "I'm new in town and I love quickly replies".

I thought that to clear (not clean? - my first language isn't English) the screen was an easy thing.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see question 20 in the Java Beginners FAQ.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Deep Narsay:

Suggestion 1 by Ernest might work, but it is not efficient since it will act character by character.


Sorry, no, not at all. All that UNIX "clear" does is send a single ANSI escape sequence -- a few characters -- to the terminal. You can do the same thing by sending the correct characters to your terminal (i.e., printing them.)

Invoking "clear" using Runtime.exec() works only if you also read the output of the process (those magic characters) and print them to System.out. Rather than starting a whole separate process, it's vastly more efficient just to print those few characters, wouldn't you say?

Note that the FAQ Marilyn points to gives the "print blank lines" solution.

Please don't contradict people who know what they're saying with your own wild-ass guesses. I've had way too much of that today already.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!