addCommand(CMD_OK);
addCommand(CMD_CANCEL);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if (c == CMD_OK) {
// update the table's cell and return
parent.setText(getString());
display.setCurrentItem(parent);
} else if (c == CMD_CANCEL) {
// return without updating the table's cell
display.setCurrentItem(parent);
}
}
}
3.8 TextField和DateField
TextField和我们前面讲的TextBox大同小异,只是它是作为Form的一个子类存在,而TextBox则是和Form平起平坐,因此我们直接给出代码方便大家的学习。

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class TextFieldWithItemStateListenerMIDlet extends MIDlet
implements ItemStateListener
{
private Display display;
public TextFieldWithItemStateListenerMIDlet()
{