2013-10-20 70 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){...} 
    };