在java代码中实现两个侦听器时出错

时间:2015-03-25 04:57:02

标签: java swing

在我的代码中,我实现了两个看起来像的侦听器:

     class Try extends JPanel  implements ActionListener, ListSelectionListener{

但在编译时显示以下错误:

 EmailTrial.java:29: error: Try is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
 class Try extends JPanel  implements ActionListener, ListSelectionListener{
 ^

请帮助解决错误的问题。如何删除此错误...

1 个答案:

答案 0 :(得分:2)

实现接口的类必须实现接口中声明的所有公共方法。因此,您需要覆盖ActionListener, ListSelectionListener方法。

class Try extends JPanel  implements ActionListener, ListSelectionListener{

 @override
 public void actionPerformed(ActionEvent e){
   // Action event code
 }

 @override
 public void valueChanged(ListSelectionEvent e){
   // Action event code
 }
}