Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Can we do this with println?

Thread view: 
neelsmail@rediffmail.com - 29 Oct 2007 13:01 GMT
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.
Roedy Green - 29 Oct 2007 13:43 GMT
>X03   |   X05   |   X07
>------------------------------
>X04   |   X02   |   X08
>------------------------------
>X01   |   X06   |   X09

You might find it easier to compose one string for each line and then
print with println.

The ---- could be done with StringTools.rep.  See
http://mindprod.com/products1.html#COMMON11

The X01  | could be done in a StringBuilder loop.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Joshua Cranmer - 29 Oct 2007 22:42 GMT
> 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)

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Roedy Green - 29 Oct 2007 23:31 GMT
On Mon, 29 Oct 2007 21:42:57 GMT, Joshua Cranmer
<Pidgeot18@verizon.invalid> wrote, quoted or indirectly quoted someone
who said :

>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.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Mark Space - 30 Oct 2007 00:04 GMT
> 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.
Roedy Green - 30 Oct 2007 02:08 GMT
On Mon, 29 Oct 2007 23:04:53 GMT, Mark Space
<markspace@sbc.global.net> wrote, quoted or indirectly quoted someone
who said :

>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.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Mark Space - 30 Oct 2007 03:16 GMT
> On Mon, 29 Oct 2007 23:04:53 GMT, Mark Space
> <markspace@sbc.global.net> wrote, quoted or indirectly quoted someone
[quoted text clipped - 4 lines]
> 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.
Joshua Cranmer - 30 Oct 2007 03:27 GMT
> On Mon, 29 Oct 2007 23:04:53 GMT, Mark Space
> <markspace@sbc.global.net> wrote, quoted or indirectly quoted someone
[quoted text clipped - 4 lines]
> 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.

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.