1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class MyCanvas extends GameCanvas {
private int y, x;
private Graphics g;
public MyCanvas() {
super(true);
setFullScreenMode(true);
x = 115;
y = 155;
g = getGraphics();
}
protected void showNotify() {
paintRect();
}
private void paintRect() {
g.setColor(255, 0, 0);
g.fillRect(x, y, 10, 10);
}
protected void keyPressed(int key) {
if (key == '8') {
y += 10;
}
if (key == '2') {
y -= 10;
}
if (key == '4') {
x -= 10;
}
if (key == '6') {
x += 10;
}
paintRect();
flushGraphics();
}
}