Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2005

Tip: Looking for answers? Try searching our database.

Clear Screen command

Thread view: 
Frank Meyer - 28 May 2005 11:48 GMT
Hi again,

does anyone know how to clear the screen where I wrote comments with
System.out.prinln("..."); ?

TIA

Best

Frank
Chris Smith - 28 May 2005 15:37 GMT
> does anyone know how to clear the screen where I wrote comments with
> System.out.prinln("..."); ?

The following code ought to work:

   public void clearScreen()
   {
       final int NUM_LINES = 100; // Just to be safe
       for (int i = 0; i < NUM_LINES; i++) System.out.println();
   }

Seriously, Java is not designed for serious console-mode user interfaces
(aka TUI).  If you need that, then you'll need to take a look at JNI
native libraries for the task... several will turn up if you Google for
"jcurses".  Java's core API console support is intended only for simple
debug/log information, and for writing UNIX-style stream-based
applications a la sed, awk, sort, wc, etc. where the standard I/O
streams are redirected or piped.  You've hit a limitation that arises
because of this fact.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Frank Meyer - 28 May 2005 17:46 GMT
Chris,

>     public void clearScreen()
>     {
>         final int NUM_LINES = 100; // Just to be safe
>         for (int i = 0; i < NUM_LINES; i++) System.out.println();
>     }

this does it - thanks :o)

Best

Frank
"." - 30 May 2005 18:13 GMT
> Chris,
>
[quoted text clipped - 5 lines]
>
> this does it - thanks :o)

If you don't have control over the number of lines on the display this is
not a good solution.

On my system my terminal console can be resized to have 160 lines of text.
This code would fail to clear the screen on my system. If my console was
somehow restricted to 100 lines then this would be an acceptable solution.

Bottom line, don't make assumptions. Whenever you see something like "Just
to be safe" it usually indicates that someone is making an assumption or
that the solution is not the best solution.

I'd use this solution for an in-house tool or something I whipped up for
personal use. I would not put this in something I shipped to a customer.

Signature

Send e-mail to: darrell dot grainger at utoronto dot ca

Chris Smith - 30 May 2005 20:03 GMT
. <darrell@does.want.spam.com> wrote:
> If you don't have control over the number of lines on the display this is
> not a good solution.

Of course this is not a good solution.  In my response, it was a preface
to explaining why clearing the screen is not actually possible in Java.  
On the other hand, if this is good enough for the OP, then obviously the
OP is not designing real-life professional-quality interfaces, and who
am I to argue?  Professional interfaces are not always a requirement.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

The Wogster - 31 May 2005 16:01 GMT
. wrote:

>>Chris,
>>
[quoted text clipped - 19 lines]
> I'd use this solution for an in-house tool or something I whipped up for
> personal use. I would not put this in something I shipped to a customer.

While that is true, perhaps there are better solutions:

1) Use a screen handling library like jcurses or jcurzez.
2) Ask the installer to specify a terminal type so you can send the
right escape codes for the terminal in question.
3) Ask the installer to specify the escape code needed or the screen
line limit.

W


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.