| Author |
Clear Screen in java?
|
Prateek Rawal
Ranch Hand
Joined: Dec 19, 2009
Posts: 90
|
|
Consider the following code:
The output of the code is:
1
2
3
4
5
6
7
8
9
10
I want the screen to get clear everytime the loop runs, although in this case it seems silly but for example i can create a new thread,make it print something and ask it to sleep, and when it wakes up i want the screen to get clear(so that i can notice the difference before clearing the screen and after clearing the screen......
So, speaking directly, i want the way to clear the screen in java.....
|
Waiting for enlightenment....
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9191
|
|
|
Check this FAQ...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6603
|
|
|
There is no simple way to do that. You might want to take a look at the link that Ankit posted. However do not go for an overkill like using another library to clear your screen. May be what you need is a method that will print 100 blank lines and you can invoke this method whenever required.
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Prateek Rawal
Ranch Hand
Joined: Dec 19, 2009
Posts: 90
|
|
There is no simple way to do that.
So you are saying that there is no method or way in Java by which i can clear the screen anytime,
thats a shocking fact....omg!!!
|
 |
Mark Uppeteer
Ranch Hand
Joined: Mar 02, 2004
Posts: 159
|
|
I once asked myself the same question (back in the days I was mostly doing C and C++) and was also shocked to hear that. But nowadays I'm not anymore and find it normal.
anyway..
try this:
in dos and read this
but you don't need to know this for your SCJP you know.
|
I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
|
 |
Prateek Rawal
Ranch Hand
Joined: Dec 19, 2009
Posts: 90
|
|
The above supposed-to-be-solution is not working, i'm getting output like this
<-[2J
1
<-[2J
2
<-[2J
3
...and so on
Is clear screen not possible in java?
Give me a definite answer, i'm not able to interpret from the link you gave me....
Can you explain it here itself?
|
 |
Dieter Quickfend
Ranch Hand
Joined: Aug 06, 2010
Posts: 280
|
|
As was stated before, clear screen doesn't depend on any programming language, it depends on an Operating system. Read Mark Uppeteer's link. The only reason clear screen doesn't work in Java is because Java is platform independent and consoles are bound to the platform.
So you're not to check java for a clear screen command, you're to check your console if it allows it, then in what way it allows it.
|
Oracle Certified Professional Java Programmer
|
 |
Prateek Rawal
Ranch Hand
Joined: Dec 19, 2009
Posts: 90
|
|
I'm doing my program on command prompt....
How can i get how to clear screen in cmd using java?
|
 |
 |
|
|
subject: Clear Screen in java?
|
|
|