【问题标题】:In Lwuit, How to handle Keypad navigation Events?在 Lwuit 中,如何处理键盘导航事件?
【发布时间】:2011-11-16 09:35:52
【问题描述】:

在我正在构建的应用程序中,我有选项卡和每个选项卡的列表。我想要的行为是当我按下左/右导航键时,选定的选项卡会改变。当我按下向上/向下导航键时,列表将更改选择索引。

我使用 LWUIT GUI builder 生成 StateMachine/StateMachineBase 类。

我整天都在努力解决这个问题。请帮忙。

【问题讨论】:

    标签: java-me lwuit lwuit-resource-editor


    【解决方案1】:

    Pheromix 的回答是正确的,但他没有考虑到UIBuilder。要覆盖 UIBuilder 中的 Form 创建覆盖方法:

    protected Component createComponentInstance(String componentType, Class cls) {
        if(cls == com.sun.lwuit.Form.class) {
            return new MyFormSubclass();
        }
        return super.createComponentInstance(componentType, cls);
    }
    

    有一个选项可以覆盖选项卡选择行为,但要获得最准确的行为,这可能是最好的方法。

    【讨论】:

      【解决方案2】:

      你为什么要把你的生活复杂化?只需在您的课程中使用 keyReleased 方法实现即可。做一个测试:

      if (display.getGameAction(keyCode) == Display.GAME_LEFT || display.getGameAction(keyCode) == Display.GAME_RIGHT)
      {
          if (tab.getSelectedIndex == 0)
              tab.setSelectedIndex(1);
          else
              tab.setSelectedIndex(0);
      }
      else if (display.getGameAction(keyCode) == Display.GAME_UP || display.getGameAction(keyCode) == Display.GAME_DOWN)
      {
          if (list.hasFocus())
              super.keyReleased(keyCode);
      }
      

      【讨论】:

      • 我也不知道为什么。我试过了,但我做不到。当我尝试从 StateMachine 类访问时,表单已经创建。我没有机会覆盖 keyRelease();刚才我能够覆盖它。但我不确定这是正确的实施方式。在 beforeMainForm() 我添加了 f.addGameKeyListener() 从那里进行选择。还是超级感谢兄弟!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 2020-06-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      相关资源
      最近更新 更多