J 2 ME Gaugeコンポーネントテスト

2312 ワード

詳細
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Gauge;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


//Gauge 
public class Gauge_test extends MIDlet implements CommandListener {
	
	private Display display;
	private Alert al;
	
	public Gauge_test(){
		display = Display.getDisplay(this);
	}
	
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		
	}

	protected void pauseApp() {
		// TODO Auto-generated method stub
		
	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		al = new Alert(" ");
		al.setType(AlertType.INFO);
		al.setTimeout(Alert.FOREVER);
		Gauge g = new Gauge(null,false,10,0);
		al.setIndicator(g);
		Command start = new Command(" ",Command.OK,1);
		Command stop = new Command(" ",Command.STOP,1);
		al.addCommand(start);
		al.addCommand(stop);
		al.setCommandListener(this);
		display.setCurrent(al);
		
	}

	public void commandAction(Command c, Displayable d) {
		// TODO Auto-generated method stub
		String cmd = c.getLabel();
		if(cmd.equals(" ")){
			AlertThread t = new AlertThread(al);
			al.setString(" ...");
			t.start();
		}else if(cmd.equals(" ")){
			notifyDestroyed();
		}
	}

}
// 
class AlertThread extends Thread{
	Alert al;
	public AlertThread(Alert al){
		this.al = al;
	}
	public void run(){
		Gauge indicator = al.getIndicator();
		for(int i= 0;i<11;i++){
			indicator.setValue(i);
			try{
				Thread.sleep(500);
			}catch(Exception ex){
				ex.printStackTrace();
			}
		}
	}
}