服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

在canvas类里调用textbox

代码

/**

* 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);

}

}

扫描关注微信公众号