import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.*;
public class GaConMid extends MIDlet implements CommandListener{
private Display d;
private Form f;
private Command cexit,cstop;
private Timer tm;
private DownloadTimer
tt;
private
Gauge gaVol;
public
GaConMid(){
d
= Display.getDisplay(this);
f = new Form("Test");
cexit = new Command("EXIT",Command.EXIT,1);
cexit = new Command("STOP",Command.ITEM,1);
gaVol = new Gauge("Gauge Progress",false,30,1);
f.append(gaVol);
f.append("Hello how are you");
f.addCommand(cstop);
f.setCommandListener(this);
}
public void startApp(){
d.setCurrent(f);
tm = new Timer();
tt = new DownloadTimer();
tm.scheduleAtFixedRate(tt,0,1000);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
public void commandAction(Command c,Displayable s){
if( c == cexit)
notifyDestroyed();
else if( c == cstop){
tm.cancel();
f.removeCommand(cstop);
f.addCommand(cexit);
gaVol.setLabel("Gauge
Cancelled");
}
}
private class DownloadTimer extends TimerTask{
public
void run(){
if(gaVol.getValue()<gaVol.getMaxValue())
gaVol.setValue(gaVol.getValue()+1);
else{
f.removeCommand(cstop);
f.addCommand(cexit);
gaVol.setLabel("Gauge
Completed");
cancel();
}
}
}
}