aspose file tools*
The moose likes Beginning Java and the fly likes Clear Screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Clear Screen" Watch "Clear Screen" New topic
Author

Clear Screen

Vishwas Hegde
Ranch Hand

Joined: Oct 02, 2003
Posts: 212
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


    GenRocket - Experts at Building Test Data
    Ernest Friedman-Hill
    author and iconoclast
    Marshal

    Joined: Jul 08, 2003
    Posts: 24184
        
      34

    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.


    [Jess in Action][AskingGoodQuestions]
    Vishwas Hegde
    Ranch Hand

    Joined: Oct 02, 2003
    Posts: 212
    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

    Joined: Jul 08, 2003
    Posts: 24184
        
      34

    There are an enormous number of resources available.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Clear Screen