the first helloworld with j2me

来源:互联网 发布:java面试题基础 编辑:程序博客网 时间:2024/05/22 16:41


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();   
  }

 }

}
 

原创粉丝点击