打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ProgressBar.java
public class ProgressBar {

    private long maximumValue = 0x64L;
    private long barLength = 0x32L;
    private char displayPattern = '\u003d';
    private char blankPattern = '\u0020';
    private char indicator = '\u003e';
    private String percentageFormat = "%.1f%%";
    private long value = 0x0L;

    public ProgressBar() {
        super();
    }

    /**
     * @param maximumValue
     */
    public ProgressBar(long maximumValue) {
        super();
        setMaximumValue(maximumValue);
    }

    /**
     * @param maximumValue
     * @param barLength
     */
    public ProgressBar(long maximumValue, long barLength) {
        super();
        setMaximumValue(maximumValue);
        setBarLength(barLength);
    }

    public void redraw() {
        if (value > maximumValue) {
            return;
        }
        long pBarLength = barLength - 9;
        long currentBarLength = 0;
        if (value == 0) {
            currentBarLength = 0;
        } else if (value == maximumValue) {
            currentBarLength = pBarLength;
        } else {
            currentBarLength = value * pBarLength / maximumValue;
        }
        String pasty = "";
        for (int i = 0; i < pBarLength; i++) {
            if (i == currentBarLength - 1 && value != maximumValue) {
                pasty += indicator;
                continue;
            }
            if (i < currentBarLength) {
                pasty += displayPattern;
                continue;
            }
            pasty += blankPattern;
        }
        System.out.printf("\r\u005b%-" + pBarLength + "s\u005d\u0020" + percentageFormat
                + "\u0020\u0020", pasty, (float) (value * 1.0 / maximumValue * 100));
    }

    /**
     * HIDE THE PROGRESS BAR
     */
    public void hide() {
        String pasty = "";
        for (int i = 0; i < barLength; i++) {
            pasty += "\u0020";
        }
        System.out.printf("\r" + pasty);
    }

    public void end() {
        end(false);
    }

    /**
     * @param hide
     */
    public void end(boolean hide) {
        if (hide) {
            hide();
        }
        System.out.printf("\r\n");
    }

    /**
     * @return the maximumValue
     */
    public long getMaximumValue() {
        return maximumValue;
    }

    /**
     * @param maximumValue
     *            the maximumValue to set
     */
    public void setMaximumValue(long maximumValue) {
        this.maximumValue = maximumValue;
    }

    /**
     * @return the barLength
     */
    public long getBarLength() {
        return barLength;
    }

    /**
     * @param barLength
     *            the barLength to set
     */
    public void setBarLength(long barLength) {
        this.barLength = barLength;
    }

    /**
     * @return the displayPattern
     */
    public char getDisplayPattern() {
        return displayPattern;
    }

    /**
     * @param displayPattern
     *            the displayPattern to set
     */
    public void setDisplayPattern(char displayPattern) {
        this.displayPattern = displayPattern;
    }

    /**
     * @return the blankPattern
     */
    public char getBlankPattern() {
        return blankPattern;
    }

    /**
     * @param blankPattern
     *            the blankPattern to set
     */
    public void setBlankPattern(char blankPattern) {
        this.blankPattern = blankPattern;
    }

    /**
     * @return the indicator
     */
    public char getIndicator() {
        return indicator;
    }

    /**
     * @param indicator
     *            the indicator to set
     */
    public void setIndicator(char indicator) {
        this.indicator = indicator;
    }

    /**
     * @return the percentageFormat
     */
    public String getPercentageFormat() {
        return percentageFormat;
    }

    /**
     * @param percentageFormat
     *            the percentageFormat to set
     */
    public void setPercentageFormat(String percentageFormat) {
        this.percentageFormat = percentageFormat;
    }

    /**
     * @return the value
     */
    public long getValue() {
        return value;
    }

    /**
     * @param value
     *            the value to set
     */
    public void setValue(long value) {
        this.value = value;
        redraw();
    }
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
c# 类操作 窗体
[Qt 练习]QProgressBar
java 把分钟 转化成 天、时 、分
java调用进度条案例
c#根据文件大小显示文件复制进度条实例
.net开发笔记(十八) winform中的等待框
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服