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

📄 eventex3.java

📁 手机K-JAVA软件学习实例
💻 JAVA
字号:
/* EventEx3.java
 * In this example, the Canvas class is subclassed to use an anonymous inner class, 
 * an implementation is provided for the keyPressed and keyReleased methods,
 * and an empty implementation is provided for the paint method.
 * When a key is pressed or released, the application prints the value of that key. 
 */
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;


public class EventEx3 extends MIDlet {
    Display display;
    Command exit;


    public EventEx3() {
        display = Display.getDisplay(this);
    }

    public void destroyApp (boolean unconditional) {
    }

    public void pauseApp () {
        System.out.println("App paused.");
    }

    public void startApp () {
       display = Display.getDisplay(this);

       Canvas canvas = new Canvas() { // anonymous class     

         public void paint(Graphics g) {
         }

         protected void keyPressed(int keyCode) {
           if (keyCode > 0) {
             System.out.println("keyPressed " +((char)keyCode));
           } else {
             System.out.println("keyPressed action " +getGameAction(keyCode));
           }                  
         }

         protected void keyReleased(int keyCode) {
           if (keyCode > 0) {
             System.out.println("keyReleased " +((char)keyCode));
           } else {
             System.out.println("keyReleased action " +getGameAction(keyCode));
           } 
         }
      }; // end of anonymous class

      exit = new Command("Exit", Command.STOP, 1);
      canvas.addCommand(exit);
      canvas.setCommandListener(new CommandListener() {
        public void commandAction(Command c, Displayable d) {
          if(c == exit) {
            notifyDestroyed();
          } else {
            System.out.println("Saw the command: "+c);
          }
        }
      });
      display.setCurrent(canvas);
    }
}

⌨️ 快捷键说明

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