Create a form with "Hello World" and add a Exit Command to exit the process.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloWorld extends MIDlet implements CommandListener {
private Display display;
private Command exitCommand;
private Form form;
public HelloWorld() {
display=Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT,1);
form=new Form("My J2ME Hello World!");
form.append("Welcome to J2ME!");
form.addCommand(exitCommand);
form.setCommandListener(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException { }
protected void pauseApp() { }
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exitCommand) {
try{
destroyApp(false);
}
catch(MIDletStateChangeException ex ){
System.out.println(ex.getMessage());
}
notifyDestroyed();
}
}
protected void startApp() throws MIDletStateChangeException {
display.setCurrent(form);
}
}
留言