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("");
// 创建一个进度条
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);
}
// 处理监听
public void commandAction(Command c, Displayable d) {
if (c == stopCommand) {
stopped = true;
stop();
}
}
// 停止时事件处理
public void stop() {
}
}