代码:--------------------------------------------------------------------------------
/**
* textbox´´s instance
*/
private textbox inputname = null;
/**
* 「cancel」command
* command in textbox
*/
private command ccancel = new command("cancel", command.cancel, 1);
/**
* 「ok」command
* command in textbox
*/
private command cok = new command("ok", command.ok, 1);
/**
* 保存在textbox中已输入的值
*/
private string name = "";
/**
* 调用textbox
* the method disposes the key pressing action
* the code of pressed key
* @param key
*/
public void keypressed(int key) {
if (key == canvas.fire) {
inputname = new textbox("请输入姓名", name, 8, textfield.any);
inputname.addcommand(ccancel);
inputname.addcommand(cok);
inputname.setcommandlistener(this);
display.getdisplay(bustroyal.instance).setcurrent(inputname);
//其中bustroyal.instance为midlet的实例
}
}
/**
* textbox中的command的处理
*/
public void commandaction(command c, displayable d) {
if (c == ccancel) {
display.getdisplay(bustroyal.instance).setcurrent(this);
} else if (c == cok) {
name = inputname.getstring().trim();
display.getdisplay(bustroyal.instance).setcurrent(this);
}
}
闽公网安备 35060202000074号