摘要行动实施

时间:2013-10-20 20:07:05

标签: java swing action jbutton abstract

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

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

                public void actionPerformed (ActionEvent e){

3 个答案:

答案 0 :(得分:1)

BingoHelper类未实现actionPerformed。扩展AbstractAction的匿名类确实实现了它,但它不是一回事。

答案 1 :(得分:1)

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

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

答案 2 :(得分:1)

JButton中删除匿名侦听器并在actionPerformed中实现BingoHelper并向其注册按钮动作侦听器

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

    //...

    b.addActionListener(this);

    //...

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

或从ActionListener移除BingoHelper界面并实施actionPerformed

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