`
1140566087
  • 浏览: 547701 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
博客专栏
2c4ae07c-10c2-3bb0-a106-d91fe0a10f37
c/c++ 入门笔记
浏览量:18076
3161ba8d-c410-3ef9-871c-3e48524c5263
Android 学习笔记
浏览量:309479
Group-logo
J2ME 基础学习课程集
浏览量:17993
A98a97d4-eb03-3faf-af96-c7c28f709feb
Spring 学习过程记录...
浏览量:17195
社区版块
存档分类
最新评论

J2ME Gauge 组件测试

    博客分类:
  • J2ME
阅读更多
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();
			}
		}
	}
}
0
5
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics