In C, by calling clrscr() from <conio.h>, we can clear a DOS screen. So how could I achieve the same action in Java?:rolleyes:
Printable View
In C, by calling clrscr() from <conio.h>, we can clear a DOS screen. So how could I achieve the same action in Java?:rolleyes:
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!
****************************************************
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?
:confused:
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!:p
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]
You can use that :
Code:public void cls()
{
for (int i = 0; i < 26 ; i ++)
System.out.println();
}
DOAK: can you change the colour of the text that appears in the console?
No sorry for that :(