Can we do this with println?

N

neelsmail

Hi,

I am new to Java programming. What I wanted to do is shown below using
a function like "System.out.println".


X03 | X05 | X07
------------------------------
X04 | X02 | X08
------------------------------
X01 | X06 | X09

In the diagram above as 'X' is any character and the remaining one is
a subscript (01, 02, 03 and so on..). What I want to do then is write
the character to the screen in the subscript order X01, X02 and so
on.. The problem is I do not get how using "System.out.println" I can
go one line above without erasing the whole screen. Of course this is
_not_ a homework but something I am trying to do nevertheless.

Any help is appreciated.

Thanks,
Neel.
 
J

Joshua Cranmer

In the diagram above as 'X' is any character and the remaining one is
a subscript (01, 02, 03 and so on..). What I want to do then is write
the character to the screen in the subscript order X01, X02 and so
on.. The problem is I do not get how using "System.out.println" I can
go one line above without erasing the whole screen. Of course this is
_not_ a homework but something I am trying to do nevertheless.

In an ANSI-compliant terminal (i.e., pretty much anything other than
Window's Command Prompt), the following string, when printed out, will
print "XXX" at the top of the screen:

"\u001B[1;1HXXX"

(see <http://en.wikipedia.org/wiki/ANSI_escape_code> for other examples)
 
R

Roedy Green

In an ANSI-compliant terminal (i.e., pretty much anything other than
Window's Command Prompt), the following string, when printed out, will
print "XXX" at the top of the screen:

without it, you can clear with a sufficiently large number of
newlines.
 
M

Mark Space

on.. The problem is I do not get how using "System.out.println" I can
go one line above without erasing the whole screen. Of course this is

This kind of cursor control is not provided by Java. It can't, really,
it's up to the output device to interpret the meaning of your output.
Joshua's pointer to ANSI escape codes was a good one.

Remember Java is just sending out a stream of characters. What meaning
does "go to the top of the screen" have when the output is being sent to
a file? None really....

If you must have control over where things get put in a more device
independent manner, Java Swing would be a good choice. You can just
draw stuff where you want with the graphics API, or you can use a
JEditorPane to put text in certain places like a word processor. All
kinda depends on your final application.
 
R

Roedy Green

This kind of cursor control is not provided by Java.

Another approach is to use a JTextArea for your "console". Then you
can even do colours and bold.
 
M

Mark Space

Roedy said:
Another approach is to use a JTextArea for your "console". Then you
can even do colours and bold.

Hmm, I'm pretty sure JTextArea only does "plain text." You might be
able to bold or color the whole thing.

JEditorPane, which I mention above, is the widget that does multiple
styles in one document, afaik.
 
J

Joshua Cranmer

Roedy said:
Another approach is to use a JTextArea for your "console". Then you
can even do colours and bold.

A third approach might be to try to find a JANSIConsole that represents
a fully ANSI-compliant terminal that provides an input and output stream.
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top