And this line must be inside the config.sys:
device=c:\windows\command\ansi.sys *************************************************************
Hi, I've already posted a question similar to yours few days ago. Luckily, I found a code that can clear off the console DOS screen in Window. However, I have big trouble in understanding the mechanism behind the code and desperately need some advice from all experts in this forum. 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?
You usually don't write command line applications in Java. That's just for really basic stuff or if it must run via a telnet connection or so, for everything that counts as real application, make your own command line window. Here's a "dirty", but simple one class implementation (usually one would use anonymous classes, but I wanted to keep it simple), that opens an own command line window, prints out some text, clears the screen after a break and after another break quits gracefully.
Compile with
javac Test.java
Start with either:
java Test
or on Windows you can use:
javaw Test
So you can close your DOS box and application continues running.
// File Test.java
import java.awt.*;
import java.awt.event.*;
publicclass Test extends Frame implements WindowListener {
privatefinal TextArea TA = new TextArea
("", 25, 80, TextArea.SCROLLBARS_NONE);
privatefinal String NEWLINE = "" + '\n';
public Test() {
TA.setEditable(false);
add(TA);
setTitle("Test Application");
setResizable(false);
addWindowListener(this);
pack();
setVisible(true);
// The last methods were inherited
// because we extend java.awt.Frame
}
publicvoid print(String s) {
TA.append(s);
}
publicvoid println(String s) {
TA.append(s);
TA.append(NEWLINE);
}
publicvoid cls() {
TA.setText("");
}
publicvoid kill() {
dispose();
}
// We must implement the following as we are
// implementing WindowListener
publicvoid windowDeactivated(WindowEvent e) {}
publicvoid windowDeiconified(WindowEvent e) {}
publicvoid windowIconified(WindowEvent e) {}
publicvoid windowOpened(WindowEvent e) {}
publicvoid windowActivated(WindowEvent e) {}
publicvoid windowClosed(WindowEvent e) {
System.exit(0);
}
publicvoid windowClosing(WindowEvent e) {
dispose();
}
publicstaticvoid main(String[] args) {
Test t = new Test();
t.println("Hello World!");
t.print("Same line ");
t.println("Test");
try {
Thread.sleep(5000); // Wait 5 seconds
} catch (InterruptedException e) {
// Do nothing, not critical to
// be interrupted
}
t.cls();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// Do nothing, not critical to
// be interrupted
}
t.kill();
}
}
Java does not support esc codes by default, you can get packages to do this for you:
http://www.pitman.co.za/projects/charva/
http://www.nongnu.org/jcurzez/
Google and this forum have a lot more information on this subject, I recomend searching for ncurses.