gaugethread.java

来自「《精通JAVA手机游戏与应用程序设计》随书光盘」· Java 代码 · 共 46 行

JAVA
46
字号


import javax.microedition.lcdui.*;


public class GaugeThread extends Gauge  implements Runnable {
	private int maxValue = 10;

    private int add = 1;

    private boolean done = false;
    
    
    public GaugeThread(String label, int maxValue,
				       int initialValue) {
        super(label, false, maxValue, initialValue);
        this.maxValue = maxValue;
        new Thread(this).start();
    }

    
    public void run() {

        while (!done) {

            int newValue = getValue() + add;

            if (newValue == maxValue) {
                add = -1;
            } else if (newValue == 0) {
                add = 1;
            }

            setValue(newValue);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException err) {
            }
        }
    }
    
    void setDone() {
        done = true;
    }
}

⌨️ 快捷键说明

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