import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
public class Exec extends MIDlet implements ItemStateListener {
private Display display;
public Exec() {
display = Display.getDisplay(this);
}
TextField name;
TextField tel;
TextField summary;
DateField date;
public void startApp() {
Form f = new Form("TextField 测试");
name = new TextField("姓名", "", 8, TextField.ANY);
tel = new TextField("电话", "", 14, TextField.PHONENUMBER);
summary = new TextField("总结", "", 60, TextField.UNEDITABLE);
date = new DateField("安排时间", DateField.DATE_TIME);
f.append(name);
f.append(tel);
f.append(summary);
f.append(date);
f.setItemStateListener(this);
display.setCurrent(f);
}
public void itemStateChanged(Item item) {
if (item == name) {
summary.setString("输入的姓名为:" + name.getString());
} else if (item == tel) {
summary.setString("输入的电话为:" + tel.getString());
} else if (item == date) {
summary.setString("输入的时间为:" + date.getDate());
} else {
summary.setString("");
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
[此贴子已经被作者于2010-12-12 18:31:16编辑过]