Canvas實現文字框
在canvas類裡呼叫textbox
private TextBox inputName = null;
private Command cCancel = new Command("cancel", Command.CANCEL, 1);
private Command cOK = new Command("ok", Command.OK, 1);
private String name = "";
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);
}
}
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);
}
}