2013-10-20 77 views
0

它不会让我运行程序因错误: 类型BingoHelper必须实现继承的抽象方法ActionListener.actionPerformed(ActionEvent)摘要行动实施

public class BingoHelper extends JFrame implements WindowListener, ActionListener{ 
JButton b = new JButton(new AbstractAction("Enter"){ 

       public void actionPerformed (ActionEvent e){ 

回答

1

BingoHelper类未实现actionPerformed。你的匿名类延伸AbstractAction确实实现它,但它不是一回事。

+0

任何解决方案? – JavaScrub

1

actionPerformed方法不是BingoHelper的成员。你应该创建一个类BingoHelper的方法并实现它。

public class BingoHelper extends JFrame implements WindowListener, ActionListener{ 
    public void actionPerformed (ActionEvent e){} 
+0

对此的任何解决方案? – JavaScrub

+0

我曾之前,它工作正常。但是我添加了一个新按钮,我想要采取其他操作,但是当我单击另一个按钮时,会出现第一个按钮的操作。 – JavaScrub

+0

当用户点击按钮时,该按钮可能会产生事件,这对组件(如按钮)很明显。这些事件将发布到事件队列中并分派给侦听它们的对象。在你的程序框架是一个监听器,它处理这种事件,无论你点击的按钮。 – 2013-10-21 08:09:55

1

要么除去从JButton匿名听者和执行内BingoHelperactionPerformed并注册按钮动作监听它

public class BingoHelper extends JFrame implements WindowListener, ActionListener { 
    JButton b = new JButton("Enter"); 

    //... 

    b.addActionListener(this); 

    //... 

    public void actionPerformed(ActionEvent evt) {...} 

或从BingoHelper除去ActionListener接口和实现的所述actionPerformed方法AbstractAction

public class BingoHelper extends JFrame implements WindowListener { 
    JButton b = new JButton(new AbstractAction("Enter"){ 
     public void actionPerformed (ActionEvent e){...} 
    };