龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

在canvas类里调用textbox

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
代码 /** * TextBoxs 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

代码

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


  
精彩图集

赞助商链接