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)建一個進度條
gauge = new Gauge("", false, MAX, 0);
stopCommand = new Command("停止", Command.STOP, 10);
addCommand(stopCommand);
append(gauge);
setCommandListener(this);
}
// 初時化進度條
public void init(String note, boolean stop) {
gauge.setValue(0);
setNote(note);
setStop(stop);
stopped = false;
}
// 進度條標題
public void setNote(String note) {
setTitle(note);
}
// 是否停止
public boolean isStop() {
return stop;
}
// 設置進度條停止
public void setStop(boolean stop) {
this.stop = stop;
}
// 是否已停止
public boolean isStopped() {
return stopped;
}
// 更新進度條
public void updateGauge() {
current = (current + 1) % LEVELS;
gauge.setValue(current * MAX / LEVELS);
}
// 處理監(jiān)聽
public void commandAction(Command c, Displayable d) {
if (c == stopCommand) {
stopped = true;
stop();
}
}
// 停止時事件處理
public void stop() {
}
}