我现在可以显示一个图片(在手机模拟器上)需要通过手机上的键盘来控制图片的移动.不知道用什么来判断.
------解决方案--------------------------------------------------------
当然是按键了啊...keypressed(int key).系统方法.然后根据key值.对图片坐标进行更改..更改同时别忘记repaint();
------解决方案--------------------------------------------------------
- Java code
public class MoveCanvas extends Canvas{ int x = 20; public void paint(Graphics g){ g.drawRect(x,50,20,10); } public void keyPressed(int keyCode){ int action = getGameAction(keyCode); switch(action){ case LEFT: x--; break; case RIGHT: x++; break; } repaint(); } }