相关代码如下
public void paint(Graphics g)
{
g.setColor(20,50,60);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.drawImage(img, x, y, g.LEFT|g.TOP);
}
protected void keyPressed(int keyCode)
{int code_1=this.getGameAction(keyCode);
if ((code_1&Canvas.DOWN)!=0&&y<100){y+=5;}
if ((code_1&Canvas.UP)!=0&&y>0){y-=5;}
if ((code_1&Canvas.LEFT)!=0&&x>0){x-=5;}
if ((code_1&Canvas.RIGHT)!=0&&x<100){x+=5;}
repaint();
}
X为横坐标,Y为纵坐标!在模拟器上面运行的时候,我按“上”键,图向右上方移动,按“左”,图向左下方移动,“右”“下”两个键是对的,没有出现其他情况