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 / First Aid / May 2005

Tip: Looking for answers? Try searching our database.

Modification of output

Thread view: 
Mikl - 29 May 2005 10:38 GMT
Hi

Right now I'm using the good ol' System.out.Println to print out to the
screen, whenever a certain variable changes. If it changes a lot, it
uses up an awful lot of lines though. Is there a way to reuse the same
line to that output so whenever it changes, it'll just overwrite the
same line?

I'm not using GUI and there are no other Println's in between the above
mentioned.

/Mikkel
Oscar kind - 29 May 2005 11:10 GMT
> Right now I'm using the good ol' System.out.Println to print out to the
> screen, whenever a certain variable changes. If it changes a lot, it
> uses up an awful lot of lines though. Is there a way to reuse the same
> line to that output so whenever it changes, it'll just overwrite the
> same line?

No, but there is a caveat to that. It depends on you knowing something
about the display device.

For example, if you know the display device is a terminal (such as a Linux
command line) you can use the ANSI escape sequences to move the cursor
around. See here for more info: http://www.termsys.demon.co.uk/vtansi.htm

Signature

Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2

Roland - 29 May 2005 12:21 GMT
> Hi
>
[quoted text clipped - 8 lines]
>
> /Mikkel

If your terminal (DOS window/Linux terminal/etc.) supports it, you can
use the carriage return character '\r' to bring the "cursor" back to the
start of the line. However, if the terminal has scrolled a line (because
the output didn't fit on /one/ terminal line), it does not get you to
where the System-out-ed line started.

public class TerminalOut
{
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            System.out.print(i);
            System.out.print('\r');
            Thread.sleep(400);
        }
    }
}

Signature

Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \



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.