GameActionTest.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- public class GameActionTest extends MIDlet {
- private Display display;
- public GameActionTest() {
- display=Display.getDisplay(this);
- }
- public void startApp() throws MIDletStateChangeException {
- display.setCurrent(new GameActionTestCanvas());
- }
- /**
- * Pause the MIDlet
- */
- public void pauseApp() {
- }
- /**
- * Called by the framework before the application is unloaded
- */
- public void destroyApp(boolean unconditional) {
- }
- class GameActionTestCanvas extends Canvas {
- private String s=" ";
- int width = this.getWidth();
- int height = this.getHeight();
- public GameActionTestCanvas() {
- //draw a 8x10 net
- }
- public void paint(Graphics g) {
- //set background to white
- g.setColor(0xFFFFFF);
- g.fillRect(0,0,width,height);
- //set foreground color to black
- g.setColor(0x000000);
- g.drawString(s,0,height/2,0);
- }
- public void keyPressed(int keycode) {
- switch(getGameAction(keycode)) {
- case Canvas.DOWN:
- s = "游戏动作:DOWN";
- break;
- case Canvas.UP:
- s = "游戏动作:UP";
- break;
- case Canvas.LEFT:
- s = "游戏动作:LEFT";
- break;
- case Canvas.RIGHT:
- s = "游戏动作:RIGHT";
- break;
- case Canvas.FIRE:
- s = "游戏动作:FIRE";
- break;
- default:
- s = "非游戏动作";
- break;
- }
- repaint();
- }
- }
- }