Basic Question

D

Da Preetham

Hi guys, Im Preetham..
Im new to Java and I still learning how to make console programs...
I wanted to know the keyword for clearing the screen in java in a
console program...
Thanks in Advance.
 
A

Andrew Thompson

Da Preetham wrote:
...
Im new to Java and I still learning how to make console programs...

That is a good way to learn, but..
I wanted to know the keyword for clearing the screen in java in a
console program...

..note that Java is not well suited to doing 'advanced'
things with consoles. It is probably better to
concentrate on learning the core Java classes,
and anytime you feel it is appropriate to clear
the console, do a loop of System.out.println("");
to print a number of blank lines.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200705/1
 
R

Robert Mark Bram

Hi Preetham,
I wanted to know the keyword for clearing the screen in java in a
console program...

There is no keyword or command for doing this, because Java doesn't
actually write to a console as such - it writes to an 'output stream',
with no understanding of whether that output stream is being displayed
on a console.. never mind what sort of console (dos, xterm etc).

Instead, what you could do is write enough empty lines to clear your
console:

for (int index = 0; index < 80; index++) {
System.out.println("");
}

The biggest problem with this is how many times should you do it? If
you say "80", you should somehow make sure that all the other people
who are going to run your app have consoles that display 80 lines or
less.

Hope this helps.

Rob
:)
 
J

Joshua Cranmer

Da said:
Hi guys, Im Preetham..
Im new to Java and I still learning how to make console programs...
I wanted to know the keyword for clearing the screen in java in a
console program...
Thanks in Advance.
Try using:

System.out.println("\u001B[2J");

That should work in all ANSI-compliant consoles.
 
D

Da Preetham

Thanks a lot
Da Preetham wrote:

..


That is a good way to learn, but..


.note that Java is not well suited to doing 'advanced'
things with consoles. It is probably better to
concentrate on learning the core Java classes,
and anytime you feel it is appropriate to clear
the console, do a loop of System.out.println("");
to print a number of blank lines.
 
D

Da Preetham

Thanks Rob.
I have one more question. Which is better c++ or java on the basis of
game programming
Thanks in advanace,
Preetham.
 
D

Da Preetham

Thanks for the info..
Ill try System.out.println("\u001B[2J");



Da said:
Hi guys, Im Preetham..
Im new to Java and I still learning how to make console programs...
I wanted to know the keyword for clearing the screen in java in a
console program...
Thanks in Advance.

Try using:

System.out.println("\u001B[2J");

That should work in all ANSI-compliant consoles.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top