import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class main extends MIDlet implements CommandListener {
private Command exitCom;
private Display ds;
private TextBox tb;
//构造函数
public main() {
// TODO Auto-generated constructor stub
ds=Display.getDisplay(this);//创建Display类一个实体
exitCom=new Command("Exit",Command.EXIT,1);//创建Command对象一个实体,并设置Exit命令用于退出这个MIDlet
tb=new TextBox("Hellow MIDlet","Hellow World",15,0);//创建用来输出东西的TextBox对象
tb.addCommand(exitCom);//使Command对象和TextBox关联起来
tb.setCommandListener(this);//当TextBox显示在屏幕上时,使CommandListener响应发生的事件
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
//当系统要求MIDlet暂停时调用
protected void pauseApp() {
// TODO Auto-generated method stub
}
//第一次启动或者暂停后重启时由系统调用startApp()方法
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
ds.setCurrent(tb);//将构造函数中的TextBox设置为当前的屏幕
}
//用户触发任何Command是,做出回应,系统会自动调用这个方法
public void commandAction(Command arg0, Displayable arg1) {
// TODO Auto-generated method stub
if(arg0==exitCom){
try {
destroyApp(false);
notifyDestroyed();
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}