clearing the screen
Hi all!
I have written a program for time tables, adding, and subtracting
for my two eight year olds. They really like the program, but they have
problems reading the lines one after another. My question is: How
do you clear the screen? In DOS, I know it is "CLS". I have a menu to where they can choose between the three items and it would be nice
if when they choose their option to clear the screen and start fresh.
Any help would be greatly appreciated. Thanks.
[509 byte] By [
zpk4026a] at [2007-9-27 23:39:51]

Java doesn't provide a method, since clearing the command window varies from system to system.
In Windows, you can write the appropriate number of empty lines to the screen [System.out.println()], or try the method below.
It requires that the system recognize ANSI escape commands. In DOS (98se and, I think, ME), that's done by adding a line "Device=ANSI.SYS (or DeviceHigh=ANSI.SYS)" to C:\config.sys. I think I've heard that XP has native support, but not sure; if the method doesn't clear the screen, then you'll need to research further.
"ANSI.SYS defines functions that change display graphics, control cursor movement, and reassign keys. The ANSI.SYS device driver supports ANSI terminal emulation of escape sequences to control your system's screen and keyboard. An ANSI escape sequence is a sequence of ASCII characters, the first two of which are the escape character (1Bh) and the left-bracket character (5Bh). The character or characters following the escape and left-bracket characters specify an alphanumeric code that controls a keyboard or display function. ANSI escape sequences distinguish between uppercase and lowercase letters; for example,"A" and "a" have completely different meanings.
This device driver must be loaded by a <DEVICE> or <DEVICEHIGH> command in your CONFIG.SYS file."
public class AnsiCode {
public static void main(String[] args) {
// Default action is to clear the screen
System.out.write(0x1B);
System.out.println((args.length == 0) ? "[2J" : args[0]);
}
}