import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.Gauge;public class GaugeUI extends Form implements CommandListener {private static final int MAX = 8;private static final int LEVELS = 8;int current = 0;Gauge gauge;Command stopCommand;boolean stop;boolean stopped;/** Creates a new instance of GaugeObserverUI */public GaugeUI() {super("");// 創(chuàng)建一個(gè)進(jìn)度條 gauge = new Gauge("", false, MAX, 0);stopCommand = new Command("停止", Command.STOP, 10);addCommand(stopCommand);append(gauge);setCommandListener(this);}// 初時(shí)化進(jìn)度條 public void init(String note, boolean stop) {gauge.setValue(0);setNote(note);setStop(stop);stopped = false;}// 進(jìn)度條標(biāo)題 public void setNote(String note) {setTitle(note);}// 是否停止 public boolean isStop() {return stop;}// 設(shè)置進(jìn)度條停止 public void setStop(boolean stop) {this.stop = stop;}// 是否已停止 public boolean isStopped() {return stopped;}// 更新進(jìn)度條 public void updateGauge() {current = (current + 1) % LEVELS;gauge.setValue(current * MAX / LEVELS);}// 處理監(jiān)聽(tīng) public void commandAction(Command c, Displayable d) {if (c == stopCommand) {stopped = true;stop();}}// 停止時(shí)事件處理 public void stop() {}}
聯(lián)系客服