站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2ME 专题抛砖引玉。判断数字键盘输入的字母。

抛砖引玉。判断数字键盘输入的字母。

摘要: 抛砖引玉。判断数字键盘输入的字母。
<tr><td>
http:///tech/article774.html

//code:本次keyPressed函数得到的key code
//pre:上次keyPressed函数得到的key code
//r:key code重复的次数。
public char getChar(int code, int pre, int r )
{
String KeyMap[] = {
"abc",
"def",
"ghi",
"jkl",
"mno",
"pqrs",
"tuv",
"wxyz"
};
char c = ' ';
[] if ((code >= KEY_NUM2) && (code <= KEY_NUM9))
{
[] int index = code - KEY_NUM2;
if (pre != code)
{
r = 0;
}
else
{
r = r % KeyMap[index].length();
[] }
c = KeyMap[index].charAt(r);
[] }
return c;
}
如果需要键入一定时间后自动确定,就用一个Timer & TimerTask:
[] keytimer = new Timer();
[] keytimer.schedule(new TimerTask(){
public void run(){
ch = getChar(code, pre, intKeyRepeat );
intKeyRepeat = 0;
}
},0,1000 );
XDJM如果有更好的方法,教教我哦。呵呵
http:///tech/article774.html
</td></tr></table></td> </tr> <tr> <td background="/pic/split.gif" height=1></td> </tr> <tr> <td class="tdMargin1">
↑返回目录
前一篇: 掌握MIDP2.0的安全结构
后一篇: 新手们,一起努力啊!——我的学习笔记