我一直在尝试如上所述实现此动作侦听器,但仍然收到两个错误:
-Cannot instantiate the type ActionListener
-void is an invalid type for the variable incrementAction
我一直在寻找类似的例子,但它们似乎都指向了实现它的相同方法。 这是我必须去的地方。
increment.addActionListener(new ActionListener());{
public void incrementAction(ActionEvent e){
this.incrementCount();
this.setTextField();
}
}
答案 0 :(得分:1)
ActionListener
方法的签名是:
public void actionPerformed(ActionEvent e)
JButton increment = new JButton();
increment.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("ActionEvent received! ");
}
});