2015-10-14 37 views
1

我有此代碼動作偵聽器的:

import java.awt.*; 
import java.applet.*; 
import java.awt.event.ActionListener; 
import java.awt.event.ActionEvent; 

public class m extends Applet 
{ 
    Button b1=new Button("click here"); 

    public void init() 
    { 
     b1.addActionListener(new ActionListener() 
     { 
      public void ActionPerformed(ActionEvent e) 
      { 
        System.out.println("Button was clicked "); 
      } 
     }); 
     add(b1); 
    } 
} 

產生這種錯誤:

error: <anonymous m$1> is not abstract and does not override abstrac method actionPerformed(ActionEvent) in ActionListener 

有沒有人知道這個錯誤是什麼原因?

+3

了'ActionListener'的覆蓋方法應該被稱爲'actionPerformed'而不是'ActionPerformed' – SomeJavaGuy

+0

可以ANY1請建議我克服這個問題在此先感謝 – sandhya

+0

@KevinEsche爲什麼不張貼此作爲一個答案? –

回答

0

您的功能ActionPerformed應該被命名爲actionPerformed。 Java方法名稱區分大小寫。

b1.addActionListener(new ActionListener() 
    { 
     @Override 
     public void actionPerformed(ActionEvent e) 
     { 
       System.out.println("Button was clicked "); 
     } 
    }); 
相關問題