GameActionTest.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.midlet.*;
  2. import javax.microedition.lcdui.*;
  3. public class GameActionTest extends MIDlet {
  4.     private Display display;
  5.     public GameActionTest() {
  6.         display=Display.getDisplay(this);
  7.     }
  8.     
  9.     public void startApp() throws MIDletStateChangeException {
  10.         display.setCurrent(new GameActionTestCanvas());
  11.     }
  12.     /**
  13.      * Pause the MIDlet
  14.      */
  15.     public void pauseApp() {
  16.     }
  17.     /**
  18.      * Called by the framework before the application is unloaded
  19.      */
  20.     public void destroyApp(boolean unconditional) {
  21.     }
  22.     class GameActionTestCanvas extends Canvas {
  23.         private String s=" ";
  24.         int width = this.getWidth();
  25.         int height = this.getHeight();
  26.         public GameActionTestCanvas() {      
  27.             //draw a 8x10 net
  28.         }
  29.         public void paint(Graphics g) {         
  30.             //set background to white
  31.             g.setColor(0xFFFFFF);
  32.             g.fillRect(0,0,width,height);
  33.             
  34.             //set foreground color to black
  35.             g.setColor(0x000000);
  36.             g.drawString(s,0,height/2,0);
  37.         }
  38.         public void keyPressed(int keycode) {
  39.             switch(getGameAction(keycode)) {
  40.             case Canvas.DOWN:
  41.                 s = "游戏动作:DOWN";
  42.                 break;
  43.             case Canvas.UP:
  44.                 s = "游戏动作:UP";
  45.                 break;
  46.             case Canvas.LEFT:
  47.                 s = "游戏动作:LEFT";
  48.                 break;
  49.             case Canvas.RIGHT:
  50.                 s = "游戏动作:RIGHT";
  51.                 break;
  52.             case Canvas.FIRE:
  53.                 s = "游戏动作:FIRE";
  54.                 break;
  55.             default:
  56.                 s = "非游戏动作";
  57.                 break;             
  58.             }
  59.            repaint();
  60.         }
  61.     }
  62. }