Results 1 to 8 of 8

Thread: How to clear DOS screen?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    12

    Question How to clear DOS screen?

    In C, by calling clrscr() from <conio.h>, we can clear a DOS screen. So how could I achieve the same action in Java?

  2. #2
    Addicted Member Mrs Kensington's Avatar
    Join Date
    Sep 2001
    Location
    Dorset, UK
    Posts
    144
    you can't. As far as i know (and do tell me if i'm wrong) there is no way of clearing the console, just as there is no way of writing to a specific co-ordinate on the console.
    If you want to do anything like that your gonna have to look at painting with guis and stuff!
    Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    12

    Red face got it ... but don't know how?

    ****************************************************
    char esc = 27;
    String clear = esc + "[2J";
    System.out.print(clear);

    And this line must be inside the config.sys:
    device=c:\windows\command\ansi.sys
    ****************************************************

    Finally, I found a code that can really clear off the console DOS screen in Window. However, I have big trouble in understanding the mechanism behind the code. Here is all the questions:

    1) Why do I need this token "[2J"? What is it used for?
    2) Why must I load the driver "ANSI.SYS" in order to have the program to work properly?
    3) What is the mechanism that drives the program to clear off the DOS screen?


  4. #4
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    looks like it relies on some native stuff by the fact it requires to you to use you config.sys. it maybe a code that is understood by your video driver as "clear screen" but that wouldn't be very portable and hence not very javaesque

    good to be back in the forum!
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  5. #5
    Lively Member
    Join Date
    Sep 2000
    Location
    Belfast
    Posts
    109
    Fill the ms-dos video buffer with null values. Normally everything shown in an ms-dos screen is stored in memory location B800H:0000H . The computer simply reads that area of memory over and over again really quicly to see what to put on the screen. If you go into ms-dos you can use microsfts debug.exe to have a look a round memory and see what's going on in the video buffer. Type the following at the command prompt (ignore the '>' signs)
    >debug
    Debug should load up if it's uncluded with your os. Now type:

    >d B800:0000
    Now you should see the contents of the screen displayed at the right hand side.

    you can change those contents by typing:
    >e B800:0000
    Put in your own vaules and see what happens to the ms-dos screen. All you need to do now is work out how to do that in java ad you'll be able to do a lot of weird and wonderful things with the ms-dos screen. This probably isn't the best way top go about doung this but it'll give you an understanding about how things are displayed in ms-dos.
    PS. It would probably help if you know some hex as each of the characters shown in an ms-dos prompt are stored as hexadecimal values and so are the atrributes (Background/foreground colour) for each character but even without knowing hex you can still do most of it. To make a blank screen just fill the video memory with zeros. If anyone gets this to work in java please email me a sample code, thanks. My email is [email protected]

  6. #6
    DaoK
    Guest
    You can use that :

    Code:
      public void cls()
      {
      for (int i = 0; i < 26 ; i ++)
        System.out.println();
      }

  7. #7
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    DOAK: can you change the colour of the text that appears in the console?
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  8. #8
    DaoK
    Guest
    No sorry for that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width