> Folowing code :
>
> for(int i = 0; i < 100; i++)
> {
>System.out.println("Progress : " + i + "%");
> ...print 100 lines to console. I want to write every
> line in 1 line.
> It is possible and how? Is there a gotoXY function
> for writting to console?
>
> Thanks.
Do you mean like this?
for(int i = 0; i < 100; i++){System.out.println("Progress : " + i + "%");}
What do you mean gotoXY?
/**
* @since August 16, 2006, 9:14 AM
* @author Ian Schneider
*/
public class DoingStuff {
public static void main(String[] args) throws Exception {
System.out.print("doing stuff ");
char[] spinner = new char[] {'|','/','-','\\'};
for (int i = 0; i < 10; i++) {
for (int j = 0; j < spinner.length; j++) {
System.out.print("\b" + spinner[j]);
Thread.sleep(250);
}
}
}
}
You could try with something like this:
System.out.print("Progress: ");
for (int i = 0; i < 100; i++) {
try {
Thread.sleep(100);
} catch (Exception e) {}
System.out.print((i <= 10 ? "\b" : "\b\b") + i);
}
Of course the code gets quite ugly when you need to move from hundreds to thousands and above...
Hope this will help.
Bye
MSL
Meanwhile, while the little twit, who is supposed to shut up, distracted
every other poster in this thread ,camickr wrote in reply #5:
> System.out.print("\rProgress: " + i);
This works fine in a dos terminal ('cmd') as well as any *nix shell I know
of. It doesn't work in eclipse's console which is a dumber than dumb
console except for its variable line length and copy/paste feature. As an
additional plus the proposed solution is way more elegant than '\b'
fiddling.
I don't think eclipse will be the 'host' for the OP's application.
kind regards,
Jos
> Meanwhile, while the little twit, who is supposed to
> shut up, distracted
> every other poster in this thread ,camickr wrote in
> reply #5:
> > System.out.print("\rProgress: " + i);
> This works fine in a dos terminal ('cmd') as well as
> any *nix shell I know
> of. It doesn't work in eclipse's console which is a
> dumber than dumb
> console except for its variable line length and
> copy/paste feature. As an
> additional plus the proposed solution is way more
> elegant than '\b'
> fiddling.
>
> I don't think eclipse will be the 'host' for the OP's
> application.
>
> kind regards,
>
> Jos
It would appear both '\b' and '\r' don't work in the BlueJ environment as well!