zoukankan      html  css  js  c++  java
  • [JavaME]在高级UI上的keyPressed事件截获的说明

    譬如说你是在一个Form上,那么有一点点不幸。
    据我所知,除非你在Form上加一个CustomItem,并且选中它,那么你的
    protected void keyPressed(int key) {
        System.out.println("Key pressed: "+key);
    }
    能够打印出你的按键。
    但是如果你当前焦点在TextField或其他lcdui.Item,那么不可能截获按键。

    如果我说错了,请指出。

    譬如说你当前是在一个Canvas上,ok,
    To "catch" an event, just implement one of

    # showNotify()
    # hideNotify()
    # keyPressed()
    # keyRepeated()
    # keyReleased()
    # pointerPressed()
    # pointerDragged()
    # pointerReleased()

    如果你特地针对keyPressed,那么:
    public class MyCanvas extends Canvas {
      MyMIDlet midlet;  // the midlet reference
      public MyCanvas(MyMIDlet m) {
        midlet = m;
      }
      protected void keyPressed(int keyCode) {
        if (getGameAction(keyCode) == Canvas.FIRE) {
          midlet.firePressed();
        }
      }
    }

    不过,值得注意的是,手机的按键并不能保证个个都能拿到,而且上下左右之类的特定意义的按键也未见得都有,所以小心。

  • 相关阅读:
    python爬取图片
    IDEA创建SpringBoot项目报错,不能连接https://start.spring.io/
    ES模块化的理解
    Web标准(网站标准)理解
    Mongodb安装
    Linux Ntp时间同步服务
    SentinelResource 注解
    Sentinel的流量控制
    Sentinel简介
    nacos安装
  • 原文地址:https://www.cnblogs.com/zhengyun_ustc/p/keypressed.html
Copyright © 2011-2022 走看看