|
26 | 26 | import javax.microedition.lcdui.game.GameCanvas; |
27 | 27 | import javax.microedition.lcdui.Image; |
28 | 28 | import javax.microedition.m3g.Graphics3D; |
| 29 | +import javax.microedition.lcdui.TextField; |
29 | 30 |
|
30 | 31 | import java.awt.image.BufferedImage; |
31 | 32 |
|
@@ -56,6 +57,9 @@ public class MobilePlatform |
56 | 57 | private int[] keyStateArr=new int[6]; |
57 | 58 | private int s=0; |
58 | 59 | private int e=0; |
| 60 | + |
| 61 | + private static int chr=-1; |
| 62 | + private static int numchr=-1; |
59 | 63 |
|
60 | 64 | public boolean suppressKeyEvents=false; |
61 | 65 |
|
@@ -123,6 +127,40 @@ public void setPainter(Runnable r) |
123 | 127 |
|
124 | 128 | public void keyPressed(int keycode) |
125 | 129 | { |
| 130 | + TextField tf=Mobile.getTextField(); |
| 131 | + if(tf!=null) |
| 132 | + { |
| 133 | + if(keycode==Mobile.KEY_NUM6 || keycode==Mobile.NOKIA_RIGHT)//替换a-z字符 |
| 134 | + { |
| 135 | + chr=(chr+1)%26; |
| 136 | + tf.replace((char)(chr+0x61)); |
| 137 | + } |
| 138 | + else if(keycode==Mobile.KEY_NUM4 || keycode==Mobile.NOKIA_LEFT)//替换a-z字符 |
| 139 | + { |
| 140 | + chr=(chr+25)%26; |
| 141 | + tf.replace((char)(chr+0x61)); |
| 142 | + } |
| 143 | + if(keycode==Mobile.KEY_NUM3)//替换0-9字符 |
| 144 | + { |
| 145 | + numchr=(numchr+1)%10; |
| 146 | + tf.replace((char)(numchr+0x30)); |
| 147 | + } |
| 148 | + else if(keycode==Mobile.KEY_NUM1)//替换0-9字符 |
| 149 | + { |
| 150 | + numchr=(numchr+9)%10; |
| 151 | + tf.replace((char)(numchr+0x30)); |
| 152 | + } |
| 153 | + else if(keycode==Mobile.KEY_STAR)//按*删除 |
| 154 | + { |
| 155 | + tf.delete(); |
| 156 | + } |
| 157 | + else if(keycode==Mobile.KEY_POUND)//按#添加新字符 |
| 158 | + { |
| 159 | + tf.append((char)(chr+0x61)); |
| 160 | + } |
| 161 | + |
| 162 | + } |
| 163 | + |
126 | 164 | updateKeyState(keycode, 1); |
127 | 165 | if(!suppressKeyEvents) |
128 | 166 | Mobile.getDisplay().getCurrent().keyPressed(keycode); |
|
0 commit comments