【问题标题】:Is there a way to change the Button.addActionListener behaviour?有没有办法改变 Button.addActionListener 的行为?
【发布时间】:2022-01-21 05:59:04
【问题描述】:

如果我在按钮上使用 .addActionListener,按钮会触发“onRelease”操作。有没有一种简单的方法可以将该行为更改为“onPress”?

我通过覆盖 pointerPressed 方法找到了解决方法。这适用于我想要实现的目标,但这是正确的方法吗?

Button button1 = new Button("LEFT"){
            @Override
            public void pointerPressed(int x, int y) {                                      
                super.pointerPress(x, y);
                m.play();               
                showLeftForm();             
            }
        };

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    所有框架都会在发布时触发而不是在新闻发布时触发。

    如果您执行后者,则发布事件将在您转换到新表单时触发,并可能导致问题。例如。屏幕转换期间的repaint() 可能会导致某些操作系统/转换组合等出现伪影。

    话虽如此,您可以根据需要使用指针按下侦听器,尽管我不建议这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-23
      • 2020-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      相关资源
      最近更新 更多