您所在的位置: 首页>>开发>>JAVA>>

在canvas类里调用textbox

http://developer.51cto.com  2005-10-10 14:36  51cto.com整理  51cto.com  我要评论(0)
  • 摘要:本文是关于如何在canvas类里调用textbox的源码
  • 标签:CA

代码

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


华硕IDC绿色节能服务器推荐
C++是垃圾语言?!
四核服务器抢鲜透视
51CTO员工上网管理辩论赛
走向银光 —— 一步一步学Silverlight2
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual C++ 6.0完全自学宝典

  • 作者:强锋科技,朱洪波
  • Visual C++ 6.0是微软公司为程序人员提供的Visual Studio 6.0工具套件中的重要组成部分。本书由浅入深地介绍使用Visual C++ 6.0..
Copyright©2005-2008 51CTO.COM 版权所有