LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2003, 07:14 PM   #1
Ginger1329
LQ Newbie
 
Registered: Nov 2003
Location: Louisiana
Posts: 1

Rep: Reputation: 0
Exclamation Clearing the Ms Dos screen in java?


Please help! how do i clear the ms dos screen that I am printing out to when writing in java. I assume that one there is an escape sequence i can't find somewhere that will clear the screen or two there is a way in insert Ms Dos commands into my java code, please someone let me know how or even if you have a suggestion!
 
Old 11-13-2003, 07:46 PM   #2
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
this works in linux, not sure if it would in windows, but i'm thinking it should.

import this:
Code:
import java.lang.Runtime;
in your class method where you want to clear the dos screen, declare a Runtime object:

Code:
Runtime rt;
and then run the rt.exec() command in your class's method:

Code:
rt.exec("cls");
that rt.exec() command takes a string for the command to run and cls is the command to clear the dos screen. hope that helps you.
 
Old 11-13-2003, 07:48 PM   #3
oulevon
Member
 
Registered: Feb 2001
Location: Boston, USA
Distribution: Slackware
Posts: 438

Rep: Reputation: 30
What do you mean by clearing the screen? I'm guessing that a MsDos screen consists of a prompt. If you want to have that not shown, you could do something along the lines of printing several newlines, so that you have several blank lines (whatever the amount you need to make the screen go blank). There is an escape sequence for this \n. So you could do something like the following:

String blank = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
System.out.println(blank);



That would give you plenty of blank lines. Is that what you mean?
 
Old 11-13-2003, 09:40 PM   #4
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
I don't think this is portable, but you can use
ANSI escape sequences to clear the screen.

Code:
public class AnsiClear {
	public static void main(String args[]) {
		String ANSI_CLEAR_SEQ = "\u001b[2J";
		String ANSI_NORMAL_SEQ = "\u001b[0m";

		System.out.println(ANSI_CLEAR_SEQ);
		System.out.println("This won't work everyhwere...");
		try {System.in.read();}catch(Exception e){}
		System.out.println(ANSI_CLEAR_SEQ);
	}
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Angry Help clearing the panel at the boto of the screen (where the aps, desktop, web A6Quattro Fedora 2 10-16-2005 10:53 PM
Help clearing the panel at the boto of the screen (where the aps, desktop, web browse A6Quattro SUSE / openSUSE 2 10-16-2005 10:17 PM
Clearing the tty console screen on logout koyi Linux - General 8 07-30-2004 11:32 AM
Clearing the screen in C++ qcoder Programming 7 11-29-2003 11:03 AM
Clearing screen xunilpassion Programming 1 10-16-2003 03:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration