gaugemidlet.java

来自「<j2me 开发精解> 詹建光著 里所有的源码。对J2me的开发相当」· Java 代码 · 共 49 行

JAVA
49
字号
package com.j2medev.sample.chapter3;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class GaugeMidlet extends MIDlet implements Runnable,CommandListener {
    
    private Display display = null;
    private Gauge gauge = new Gauge("进度条", false, 99, 0);
    private Form form = new Form("UIDemo");
    private Command exitCommand = new Command("退出",Command.EXIT, 1);
    
    public void startApp() {
        if(display==null) {
            display = Display.getDisplay(this);
            form.append(gauge);
            form.addCommand(exitCommand);
            form.setCommandListener(this);
            display.setCurrent(form);
            //启动线程更新进度条
            new Thread(this).start();
        }
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void run() {
        //当Gauge当前值小于最大值得时候,执行+1操作
        while(gauge.getValue()<gauge.getMaxValue()) {
            gauge.setValue(gauge.getValue()+1);
            try {
                Thread.sleep(100);
            } catch(InterruptedException ie) {}
        }
    }
    
    public void commandAction(Command cmd,Displayable displayable){
        if(cmd == exitCommand){
            destroyApp(false);
            notifyDestroyed();
        }
    }
    
}

⌨️ 快捷键说明

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