• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clear Screen

 
Vishwas Hegde
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

i just wanted to know... is there any method to Clear Screen.

Like clrscr() in c & c++???

Regards
Vishwas
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vishwas Hegde:
Hi.

i just wanted to know... is there any method to Clear Screen.

Like clrscr() in c & c++???

Regards
Vishwas


A. No, there are 2 ways to try though.
  • Issue enough System.out.println("") to scroll the screen clear
  • Use Runtime.exec("...") and issue the appropriate clear screen command for whatever OS you are on.


  • B. clrscr() is not a portable C/C++ function and is only available in Borlands compiler. Visual C++ you can do something like system("CLS") which is equivelent to my second suggestion above.
     
    Ernest Friedman-Hill
    author and iconoclast
    Marshal
    Pie
    Posts: 24211
    35
    Chrome Eclipse IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    To add a third option to what Gregg said, many terminals support ANSI escape sequences. If yours does, then your Java program can print the ANSI "clear screen" sequence to clear the screen. This program will clear the terminal window on many systems:




    ANSI escapes are great: you can display colors, move the cursor around, etc. They will work on Windows and on UNIX platforms.
     
    Vishwas Hegde
    Ranch Hand
    Posts: 212
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hello,

    Thanks for the reply.

    The first Option leaves the cursor at the end of the screen

    The second Option.... i didnt get....dont know why!!??
    ( I am using windows 98 and "cls" is the command for clear screen in DOS.)

    The Third Option also didnt work for me in the beginning. But later got to know that we need to add this in the Config.sys.

    device=c:\windows\command\ansi.sys

    restart it and then if we compile our program... it works!!!

    ***************************

    I was searching for this only..... But can u please tell me how it works. Is there any web site, ebooks or any books for learning more about ANSI escapes ( about colors and moving the cursor) ..... Please let me know... i am very much interested.

    Once again thanks for the help

    Regards
    Vishwas
    SCJP1.4
     
    Ernest Friedman-Hill
    author and iconoclast
    Marshal
    Pie
    Posts: 24211
    35
    Chrome Eclipse IDE Mac OS X
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic