NonInteractiveGaugeRunnable.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.lcdui.*;
- public class NonInteractiveGaugeRunnable extends Gauge implements Runnable {
- private int maxValue = 10;
- private int delta = 1;
- private boolean isRun = false;
- private boolean isStop = false;
- public NonInteractiveGaugeRunnable(String label, int maxValue,
- int initialValue) {
- super(label, false, maxValue, initialValue);
- this.maxValue = maxValue;
- new Thread(this).start();
- }
- public void run() {
- while (!isRun) {
- // decide whether the gauge should start moving
- // backwards or forwards.
- if(!isStop){
- int newValue = getValue() + delta;
- if (newValue == maxValue) {
- delta = -1;
- } else if (newValue == 0) {
- delta = 1;
- }
- setValue(newValue);
- }
- try {
- Thread.currentThread().sleep(1000);
- } catch (InterruptedException err) {
- }
- }
- }
- void setDone() {
- isRun = true;
- }
- void reStart(){
- isStop = false;
- }
- void stop(){
- isStop = true;
- }
- }