Netbeans 当我按下选择或箭头按钮时,ActionListener未收到actionperformed事件

Netbeans 当我按下选择或箭头按钮时,ActionListener未收到actionperformed事件,netbeans,java-me,lwuit,Netbeans,Java Me,Lwuit,我不明白它为什么不接收动作事件。我按下箭头和选择按钮,仍然没有任何输出到控制台 import com.sun.lwuit.events.*; public class LWUITAPP extends javax.microedition.midlet.MIDlet implements ActionListener, CommandListener { Form form = new Form(); form.show(); form.addC

我不明白它为什么不接收动作事件。我按下箭头和选择按钮,仍然没有任何输出到控制台

import com.sun.lwuit.events.*;
public class LWUITAPP extends javax.microedition.midlet.MIDlet implements ActionListener, CommandListener {

        Form form = new Form();
        form.show();
        form.addComponent(list);

        list.setModel(model);
}



public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void actionPerformed(ActionEvent evt) {
    System.out.println ("hii!");
    System.out.println(evt.getKeyEvent());
}

public void commandAction(Command c, Displayable d) {

}
}

您忘记将
键侦听器
放入
表单
。您必须将此addKeyListener/addGameKeyListener附加到
表单
。这应该行得通。

好吧:我会尽量保持冷静

要注册事件,必须添加行

Form form = new Form();
> form.addCommandListener(this)
form.show()
…以便通过actionPerformed方法收听事件

作为证明,请看一下LWUIT API的这一页。


有趣的是,addCommandListener()方法是在Swing应用程序中通常使用addActionListener()的地方实现的

我想你在“公开课”之后就少了一些东西;要么这样,要么你在结尾有一个无关的“}”。