Hey people,
I'm just talking about the Java Language being used for console output. Can we clear the screen like how we can in C++ by just the clrscr(); call??
If not is there a gotoxy() function in Java? Because if there is one, the following can be done:
1) Output a Blank on 80 Lines
2) gotoxy(0,0);
can Anybody help me?
Thanx,
Sanchit
Clearing The Screen?Can this be done?
33 Replies - 80446 Views - Last Post: 18 April 2010 - 11:18 PM
Replies To: Clearing The Screen?
#2
Re: Clearing The Screen?
Posted 21 December 2004 - 10:54 AM
Good question. There is no clear screen command for console apps in java, unless one has been developed recently (I'm doubtful). That's the price one has to pay for platform independance. As noted, you can simulate it by ourputting several endlines or spaces, but then your cursor is at the bottom of the screen. there is a java implementation of the ncurses library here which may be of some help, maybe not.
#3
Re: Clearing The Screen?
Posted 21 December 2004 - 11:09 AM
When I used to program in Java I used a command to do it but I'm pretty sure it was library specific. When I get home tonight I'll check some of my leftover code and to verify for you though.
#4
Re: Clearing The Screen?
Posted 21 December 2004 - 01:55 PM
You're likely to be better off calling a O/S specific command. Something like:
This is not perfect but the task you want to do is somewhat O/S specific. However, the advantage is that you do not need to assume a particular screen size and configuration.
String clearScreenCommand = null; if( System.getProperty( "os.name" ).startsWith( "Window" ) ) clearScreenCommand = "cls"; else clearScreenCommand = "clear"; Runtime.getRuntime().exec( clearScreenCommand );
This is not perfect but the task you want to do is somewhat O/S specific. However, the advantage is that you do not need to assume a particular screen size and configuration.
#5
Re: Clearing The Screen?
Posted 22 December 2004 - 06:25 AM
Yeah, that's always an option, just keep in mind you'll lose the independant nature of Java. Of course, you can try and take into consideration as many OS specific commands as you can. Point in fact, I'm sure most of your users will be runiing one of the major OS's to begin with, so you could probably just get away with the standards.
#6
Re: Clearing The Screen?
Posted 22 December 2004 - 09:20 AM
Well...i guess that code should work for Windows...thanks anyway
#7
Re: Clearing The Screen?
Posted 22 December 2004 - 02:42 PM
born2c0de, on Dec 22 2004, 09:20 AM, said:
Well...i guess that code should work for Windows...thanks anyway
The code should work for Windows and the vast majority of Unix variants (I'm sure it'll work on Linux, BSD, and Solaris). What it won't work on is OS/400, MVS, and other O/S's that would require a switch statement type of construct. Sorry, but my CICS is pretty rough and I'm not sure how to clear the screen on a 3270 terminal
#8
Re: Clearing The Screen?
Posted 03 January 2005 - 03:19 AM
thanks...code works fine with Windows and Linux.
#9
Re: Clearing The Screen?
Posted 12 March 2005 - 05:41 PM
I was also wondering how to do this... but now it seems ive ran into a differnt problem
When i try the code posted by stdunbar the JVM throws an IOException. Does anyone know why this might be happening?
When i try the code posted by stdunbar the JVM throws an IOException. Does anyone know why this might be happening?
#12
Re: Clearing The Screen?
Posted 13 March 2005 - 09:51 PM
i guess just try this code out:
Runtime.getRuntime().exec("cls");
#13
Re: Clearing The Screen?
Posted 13 March 2005 - 10:30 PM
that is the line that is throwing the exception. thows the same IOException just by itself too.
#14
Re: Clearing The Screen?
Posted 06 October 2006 - 08:12 AM
born2c0de, on 21 Dec, 2004 - 10:41 AM, said:
Hey people,
I'm just talking about the Java Language being used for console output. Can we clear the screen like how we can in C++ by just the clrscr(); call??
If not is there a gotoxy() function in Java? Because if there is one, the following can be done:
1) Output a Blank on 80 Lines
2) gotoxy(0,0);
can Anybody help me?
Thanx,
Sanchit
I'm just talking about the Java Language being used for console output. Can we clear the screen like how we can in C++ by just the clrscr(); call??
If not is there a gotoxy() function in Java? Because if there is one, the following can be done:
1) Output a Blank on 80 Lines
2) gotoxy(0,0);
can Anybody help me?
Thanx,
Sanchit
born2c0de, on 21 Dec, 2004 - 10:41 AM, said:
Hey people,
I'm just talking about the Java Language being used for console output. Can we clear the screen like how we can in C++ by just the clrscr(); call??
If not is there a gotoxy() function in Java? Because if there is one, the following can be done:
1) Output a Blank on 80 Lines
2) gotoxy(0,0);
can Anybody help me?
Thanx,
Sanchit
I'm just talking about the Java Language being used for console output. Can we clear the screen like how we can in C++ by just the clrscr(); call??
If not is there a gotoxy() function in Java? Because if there is one, the following can be done:
1) Output a Blank on 80 Lines
2) gotoxy(0,0);
can Anybody help me?
Thanx,
Sanchit
for (int i =0;i<400;i++)
System.out.println("");
#15
Re: Clearing The Screen?
Posted 29 March 2007 - 10:01 AM
I'm bumping this because I'm getting the same exception using Windows XP and I didn't see a resolution. In this situation, I don't care about platform independence. I'm just making a very quick and very dirty console app to test something.
This code
Yields this exception
Anyone?
This code
try {
Runtime.getRuntime().exec("cls");
} catch (IOException e) {
e.printStackTrace();
}
Yields this exception
java.io.IOException: CreateProcess: cls error=2 at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.<init>(Unknown Source) at java.lang.ProcessImpl.start(Unknown Source) at java.lang.ProcessBuilder.start(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) ...
Anyone?

New Topic/Question
This topic is locked


MultiQuote




|