gaugedemo.java
来自「j2me学习 简单例子」· Java 代码 · 共 94 行
JAVA
94 行
package example.demoseniorui.gauge;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* <p>J2ME Gauge Demo</p>
*
* @author 刘光辉
* @version 2009.02.01
*/
public class GaugeDemo extends MIDlet implements CommandListener{
private static final Command CMD_EXIT = new Command("EXIT",Command.EXIT,1);
private Display display;
private Form mainForm;
private NonInteractiveGaugeRunnable nonInteractive;
private IncrementalIndefiniteGaugeRunnable indefinite;
/**
* <p>GaugeDemo的构造函数</p>
*/
public GaugeDemo() {
display = Display.getDisplay(this);
mainForm = new Form("GaugeDemo");
mainForm.append(new Gauge("Interactive",true,10,0));
nonInteractive = new NonInteractiveGaugeRunnable("Non Interactive", 10, 0);
new Thread(nonInteractive).start();
mainForm.append(nonInteractive);
mainForm.append(new Gauge("Indefinite - Running", false, Gauge.INDEFINITE,
Gauge.CONTINUOUS_RUNNING));
indefinite = new IncrementalIndefiniteGaugeRunnable("Indefinite - Incremental");
new Thread(indefinite).start();
mainForm.append(indefinite);
mainForm.addCommand(CMD_EXIT);
mainForm.setCommandListener(this);
}
/**
* <p>启动程序,使MIDlet处于active状态</p>
* <p></p>
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException {
display.setCurrent(mainForm);
}
/**
* <p>暂停程序,使MIDlet处于pause状态</p>
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp() {
}
/**
* <p>销毁程序,使MIDlet处于destroyed状态</p>
*
* @param boolean unconditional
* <ul>true 释放资源保存数据进入destroyed状态,false 抛出异常保持当前状态</ul>
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
nonInteractive.setDone();
indefinite.setDone();
}
/**
* <p>命令处理函数,实现CommandListener接口</p>
* @param Command c 命令对象
* @param Displayable d 被放置到显示屏显示的对象
*/
public void commandAction(Command c, Displayable d) {
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
notifyDestroyed();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?