日期:2014-05-20 浏览次数:20852 次
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
/**
* @author Administrator
*/
public class Tex extends MIDlet implements CommandListener {
private Display dis;
private TextBox tb;
private Command exit, input;
private List conL;
static final String[] conN = { "any", "Num", "Email", "shi zhi", "phone",
"URL", };
static final int[] conT = { TextField.ANY, TextField.NUMERIC,
TextField.EMAILADDR, TextField.DECIMAL, TextField.PHONENUMBER,
TextField.URL, };
public Tex() {
dis = Display.getDisplay(this);
exit = new Command("退出", Command.SCREEN, 1);
tb = new TextBox("", "", 200, 0);
conL = new List("选择类型", Choice.IMPLICIT, conN, null);
tb.addCommand(exit);
tb.setCommandListener(this);// 注册监听器
conL.addCommand(exit);
conL.setCommandListener(this);
}
public void startApp() {
dis.setCurrent(conL);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (d.equals(conL)) {
if (c == exit) {
destroyApp(false);
notifyDestroyed();
}
int t = ((List) d).getSelectedIndex();
tb.setTitle(conN[t]);
tb.setConstraints(conT[t]);
dis.setCurrent(tb);
} else if (d == tb) {// 当前是TextBox
if (c == exit) {// 按退出,返回到List
dis.setCurrent(conL);
}
}
}
}