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_/ /__/
/ \ /_/ / \