Article View: comp.lang.java.help
Article #73Re: system.out.println() I need to know about "\t" and others....
From: Mike Lundy
Date: Fri, 08 Sep 2000 05:57
Date: Fri, 08 Sep 2000 05:57
85 lines
3739 bytes
3739 bytes
jobi
as your class isn't static, retain the argument 'display text' globally within the constuctor, and then :
import java.io.*;
public class ProgressStatus {
private short currentPercentage ;
private short newpPercentage ;
private String displayText;
public ProgressStatus(String displayText) {
this.displayText = displayText;
currentPercentage = 0 ;
System.out.flush() ;
}
public void updateProgress(long current, long total) {
newpPercentage = (short)((float)current/total*100) ;
if (newpPercentage != currentPercentage) {
//Update the new %
System.out.print("\r" + displayText + newpPercentage + "%") ;
//Update the Internal
currentPercentage = newpPercentage ;
System.out.flush() ;
}
}
}
the "\r" returns the cursor to the start of the current line, therefore
each updateProgress(long current, long total) call fully overwrites the
complete diplayed text on the current line of the console
hope this helps...
-mike-
.
Jobi wrote:
>
> Hi,
> I have just finished a small java application but I would like to improve on
> it a bit . I am trying to display some progress Information. Here is what I
> would like the output to look like:
>
> Zipping File: 14%
>
> I would like to be able to change the 14% to its new value but all I seem to
> be able to do is 14%15%16%......
>
> is there a code I can Use? Here is my Class Definition:
>
> import java.io.*;
> public class ProgressStatus {
> private short currentPercentage ;
> private short newpPercentage ;
> public ProgressStatus(String displayText) {
> System.out.print(displayText+": 0%") ;
> currentPercentage = 0 ;
> System.out.flush() ;
> }
> public ProgressStatus(String displayText, long current, long total) {
> System.out.print(displayText+": 0%") ;
> currentPercentage = 0 ;
> updateProgress(current, total) ;
> }
> public void updateProgress(long current, long total) {
> newpPercentage = (short)((float)current/total*100) ;
> if (newpPercentage != currentPercentage) {
> //Update the new %
> System.out.print("\b"+newpPercentage+"%") ;
> //Update the Internal
> currentPercentage = newpPercentage ;
> System.out.flush() ;
> }
> }
> }
>
> I was hoping that there would be a "\?" available such as "\t" for Tabs
> Any Ideas?
>
> Thanks
>
> ejodoin@home.com
Technical Details
Message-ID:
<39B87FC2.FBEC1AB7@osgltd.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-east!supernews.com!news-feed.riddles.org.uk!nntp.cs.ubc.ca!nntp.itservices.ubc.ca!paralynx!van-bc!deep!not-for-mailReferences:
<J9Vt5.3862$x6.216193@news1.gvcl1.bc.home.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d6b,eaca0815bc6f7f3b X-Google-Attributes: gid111d6b,public X-Google-Thread: f74b3,eaca0815bc6f7f3b X-Google-Attributes: gidf74b3,public X-Google-Thread: 113ae9,eaca0815bc6f7f3b X-Google-Attributes: gid113ae9,public X-Google-ArrivalTime: 2000-09-07 23:00:40 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-east!supernews.com!news-feed.riddles.org.uk!nntp.cs.ubc.ca!nntp.itservices.ubc.ca!paralynx!van-bc!deep!not-for-mail Message-ID: <39B87FC2.FBEC1AB7@osgltd.com> Date: Thu, 07 Sep 2000 22:57:22 -0700 From: Mike Lundy <lundy@osgltd.com> X-Mailer: Mozilla 4.05 [en]C-AtHome0404 (Win95; U) MIME-Version: 1.0 Newsgroups: comp.lang.java.help,comp.lang.java.misc,borland.public.jbuilder.java.language To: Jobi <ejodoin@home.com> Subject: Re: system.out.println() I need to know about "\t" and others.... References: <J9Vt5.3862$x6.216193@news1.gvcl1.bc.home.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 85 NNTP-Posting-Host: l011.kel.dial.paralynx.net X-Trace: deep 968392659 2411 209.52.141.11