📄 navigate2canvas.java
字号:
import javax.microedition.lcdui.*;
class Navigate2Canvas extends Canvas {
int width = 0;
int height = 0;
private Image image;
private int newX=0;
private int newY=0;
private int stepX=0;
private int stepY=0;
public Navigate2Canvas(Image image) {
this.image=image;
newX=0;
newY=0;
stepX = getWidth()/4;
stepY = getHeight()/4;
}
public void steppingXY(int x, int y) {
newX += x;
newY += y;
}
public void paint(Graphics g) {
width=this.getWidth();
height=this.getHeight();
g.setGrayScale(255);
g.fillRect(0,0,width-1,height-1);
g.setGrayScale(0);
g.drawRect(0,0,width-1,height-1);
g.translate(newX, newY);
g.drawImage(image,0,0, g.TOP|g.LEFT);
}
protected void keyPressed(int keyCode){
int gameaction = getGameAction(keyCode);
switch(gameaction){
case UP:steppingXY(0,stepY);
break;
case DOWN:steppingXY(0,-stepY);
break;
case LEFT:steppingXY(stepX,0);
break;
case RIGHT:steppingXY(-stepX,0);
break;
}
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -