当我按下“选择”或箭头按钮时,ActionListener 没有收到任何操作执行事件
我不明白为什么它没有收到操作事件。我按下箭头并选择按钮,但仍然没有任何内容输出到控制台。
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) {
}
}
I can't figure out why it isn't receiving the action event. I push the arrows and select button and still nothing gets output to the console.
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) {
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记将
keyListener
放入Form
中。您必须将此 addKeyListener/addGameKeyListener 附加到Form
。这应该有效。You forget to put the
keyListener
to theForm
. You must put this addKeyListener/addGameKeyListener attached to theForm
. This should work.好吧:我会尽力保留它 SSCCE。
为了注册事件,您必须添加行...
...以便通过您的actionPerformed 方法监听事件。
作为我的证明,请查看 LWUIT API 上的此页面。
https:// /lwuit.java.net/javadocs/com/sun/lwuit/Form.html#addCommandListener(com.sun.lwuit.events.ActionListener)
有趣的是,addCommandListener() 方法的实现取代了 Swing 应用程序中通常使用的 addActionListener() 方法。
All right: I will try to keep it SSCCE.
In order to have events registered, you must add the line...
...in order to listen to events through your actionPerformed method.
As my proof, take a look at this page on the LWUIT API.
https://lwuit.java.net/javadocs/com/sun/lwuit/Form.html#addCommandListener(com.sun.lwuit.events.ActionListener)
Interestingly, the addCommandListener() method is implemented in place of where addActionListener() would normally be used in the case of Swing applications.