gauge怎么滚动的不对呀?
小弟照着书写了一个进度条的例程,就是10格子的进度条,每秒走一格。可是不知道为什么每次走到5格就停止了。我输出了走格子的变量,它是一直走到10的,不知道怎么回事。哪位好心人指点一下。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class AlertDemo extends MIDlet implements CommandListener{
private final static Command CMD_EXIT =new Command( "Exit ",Command.EXIT ,1);
private Alert alert;
private Form form;
private final int timeout=10000;
public AlertDemo()
{
alert = new Alert( "AlertDemo ", "Information Alert Rujnig ",null,AlertType.INFO );
form = new Form( "Next Screen ");
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() {
// TODO Auto-generated method stub
Display.getDisplay(this).setCurrent(alert,form);
alert.setTimeout(timeout);
Gauge indicator=createIndicator(timeout);
alert.setIndicator(indicator);
form.append( "Alert has done! ");
form.addCommand(CMD_EXIT);
form.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
// TODO Auto-generated method stub
if (c==CMD_EXIT)
{
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
}
}
public Gauge createIndicator(int maxValue)
{
if(maxValue==Alert.FOREVER)
{
return new Gauge(null,false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING);
}
final int max=maxValue/1000;
System.out.println(max);
final Gauge indicator=new Gauge(null,false,max,0);
new Thread()
{
public void run()
{
int value=0;
while(value <max)
{
indicator.setValue(value++);
System.out.println(value);
try
{
Thread.sleep(1000);
}
catch(Exception e)