⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameactiontest.java

📁 j2me方向的控制的演示,手机上的up,down,left,right等的控制的和显示
💻 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();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -