import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.Form;
public class HelloWorld extends MIDlet implements CommandListener {
private Display display;
private Form form;
private Command command;
public HelloWorld() {
super();
// TODO Auto-generated constructor stub
form = new Form("test");
form.append("Hello World !");
command = new Command("Exit",Command.EXIT,1);
form.addCommand(command);
form.setCommandListener(this);
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
display = Display.getDisplay(this);
display.setCurrent(form);
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void destroyApp(boolean arg0) {
// TODO Auto-generated method stub
form = null;
}
public void commandAction(Command arg0, Displayable arg1) {
// TODO Auto-generated method stub
if(arg0 == command){
destroyApp(true);
notifyDestroyed();
}
}
}
本文提供了一个简单的Java MIDP (Mobile Information Device Profile) 应用示例——HelloWorld程序。该程序通过实现CommandListener接口响应退出命令,并展示了如何创建显示'Hello World!'的基本界面。
1467

被折叠的 条评论
为什么被折叠?



