customitemdemo.java
来自「j2me学习 简单例子」· Java 代码 · 共 89 行
JAVA
89 行
package example.demoseniorui.custom;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* <p>J2ME CustomItem Demo</p>
*
* @author 刘光辉
* @version 2009.02.01
*/
public class CustomItemDemo extends MIDlet implements CommandListener {
private static final Command CMD_EXIT = new Command("退出",Command.EXIT,1);
private Display display;
private boolean firstTime;
private Form mainForm;
/**
* <p>CustomItemDemo的构造函数</p>
*/
public CustomItemDemo() {
firstTime = true;
mainForm = new Form("Custom Item");
}
/**
* <p>启动程序,使MIDlet处于active状态</p>
* <p>在这个方法里声明了一个Form,用来放置Custom Item</p>
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException {
if(firstTime){
display = Display.getDisplay(this);
mainForm.append(new TextField("UpperItem",null,10,0));
mainForm.append(new Table("Table",Display.getDisplay(this)));
mainForm.append(new TextField("LowerItem",null,10,0));
mainForm.addCommand(CMD_EXIT);
mainForm.setCommandListener(this);
firstTime = false;
}
display.setCurrent(mainForm);
}
/**
* <p>暂停程序,使MIDlet处于pause状态</p>
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp() {
}
/**
* <p>销毁程序,使MIDlet处于destroyed状态</p>
*
* @param boolean unconditional
* <ul>true 释放资源保存数据进入destroyed状态,false 抛出异常保持当前状态</ul>
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
/**
* <p>命令处理函数,实现CommandListener接口</p>
* @param Command cmd 命令对象
* @param Displayable d 被放置到显示屏显示的对象
*/
public void commandAction(Command cmd, Displayable d) {
if(cmd == CMD_EXIT){
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?