How to clear screen in Java?

Status
Not open for further replies.

redhat

Mad and Furious
Hi,
I am creating a project in Java for my std. 10th Boards...

I need to know how to clear(flush) the command prompt screen from a code.
Like its "clrscr()" in C.

Actually its a menu driven program and I need to clear the screen after an option is selected, to make clean space for the next menu...

waiting for a reply...........
 

QwertyManiac

Commander in Chief
By default there is no function in Java that does this, cause its platform independent.

The only way to do so is to call up the CMD's 'cls' function and this thing makes the code messy and sometimes doesn't work out on the same window as your program. But anyway, the code for that'd be:

Code:
Runtime.getRuntime().exec("cmd cls");

Or maybe you can print a few blank lines via a loop to fake it. But trust me, thats way better than calling up the command's 'cls' and making your code messy all over.

Also, it isn't really that important to refresh the screen and start all over, just to make it look better. Instead, concentrate on your functionalities of the program.
 

~Phenom~

The No.1 Stupid
^^yeah . I was also about to say:"If U cant make it , fake it." A year back , I also wanted to do the same as redhat and used blank lines in loops . I was not aware of the method qwerty said, donno if it really works.
 

bazigaar_no_1

Broken In
exactly... that's whay i did in my 10th standard project... create a new class (with a constructor) just having a loop that prints 30 new blank lines... so everytime you wanted to clear the screen just make an object of that class ..
 
Status
Not open for further replies.
Top Bottom