progresscanvas.java

来自「DOJA平台赛车游戏」· Java 代码 · 共 77 行

JAVA
77
字号
/*
 * @(#)ProgressCanvas    1.0 04/07/01 @(#)
 *
 * Copyright 2004 NTT DoCoMo, Inc. All rights reserved.
 */
import com.nttdocomo.ui.Canvas;
import com.nttdocomo.ui.Graphics;

/** 
 * ProgressCanvas<BR>
 * The load status screen of the image.
 * <br>
 * <p>
 * @version 1.0
 * </p>
 */
public class ProgressCanvas extends Canvas {
    /** Maximum of ProgressBar */
    private int max = 0;
    /** Progress */
    private int current = 0;

    /** Message */
    private String message = null;

    /**
     * Constructor.
     * @param _max Maximum of ProgressBar
     */
    public ProgressCanvas(int _max) {
        reset(_max);
    }

    /**
     * Initialization
     * @param _max Maximum of ProgressBar
     */
    public void reset(int _max) {
        this.max = _max;
        current = 0;
        message = "";
    }

    /**
     * Advances
     */
    public void add() {
        current++;
        repaint();
    }

    /**
     * Sets a message.
     * @param _message 儊僢僙乕僕
     */
    public void setMessage(String _message) {
        this.message = _message;
    }

    /*
     * @see com.nttdocomo.ui.Frame#paint(com.nttdocomo.ui.Graphics)
     */
    public void paint(Graphics g) {
        int width = this.getWidth() - 10;
        g.lock();
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        g.setColor(Color.WHITE);
        g.drawString(this.message, 5, this.getHeight() / 2 - 15);
        g.setColor(Color.GRAY);
        g.fillRect(5, this.getHeight() / 2 - 10, width, 20);
        g.setColor(Color.BLUE);
        g.fillRect(5, this.getHeight() / 2 - 10, width * current / max, 20);
        g.unlock(true);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?