🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.help
3 messages
3 total messages Started by Jobi Thu, 07 Sep 2000 23:04
system.out.println() I need to know about "\t" and others....
#71
Author: Jobi
Date: Thu, 07 Sep 2000 23:04
44 lines
2714 bytes
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
Re: system.out.println() I need to know about "\t" and others....
#72
Author: Dima Maziuk
Date: Fri, 08 Sep 2000 04:53
18 lines
1946 bytes
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%
 
"\r" is what you're looking for. System.out.print("\rZipping file " ...

Dima
--
"The phrase "Login to www.clue.org and issue the GET command" springs to
mind..."
        -- Tanuki the Raccoon-dog in the monastery 
--------------------------------------------------
Setting Orange, 31 Bureaucracy 3166, 0:0:21 (1)
Re: system.out.println() I need to know about "\t" and others....
#73
Author: Mike Lundy
Date: Fri, 08 Sep 2000 05:57
85 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads