How can I write in 1 line?

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
[298 byte] By [ptibull77a] at [2007-10-3 2:51:42]
# 1

> 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?

zadoka at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 2
You mean instead of 1234you want1 2 3 4?If so, then change println to print.gotoXY? If you want to place stuff at arbitrary locations on the console, maybe google for java curses or something.
jverda at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 3

/**

* @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);

}

}

}

}

IanSchneidera at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 4

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

masseliaa at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 5
System.out.print("\rProgress: " + i);
camickra at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 6
Yes, it is. '\b' parameter. Thanks a lot of.But, I have a one question. It work under console corectly, but it doesn't workunder console in Eclipse SDK. Could you tell me why?Thank you.
ptibull77a at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 7
because eclipse doesn't process the \b character correctly?
IanSchneidera at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 8
> because eclipse doesn't process the \b character correctly?Is there some way how fix it?
ptibull77a at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 9

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

JosAHa at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...
# 10

> 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!

theApprenticea at 2007-7-14 20:40:36 > top of Java-index,Java Essentials,Java Programming...