在我的代码中,我实现了两个监听器,如下所示:
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{
^
请帮助解决问题以及如何消除此错误...
最佳答案
实现接口(interface)的类必须实现接口(interface)中声明的所有公共(public)方法。因此,您需要重写 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
}
}
关于java - 在java代码中实现两个监听器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29247759/