内部类构造失败
程序代码:
package innerClass; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.Timer; import java.util.*; public class InnerClass { public static void main(String[] args) { TalkingClock clock=new TalkingClock(1000, true); clock.start(); JOptionPane.showMessageDialog(null, "推出程序"); System.exit(0); } } class TalkingClock { private int interval; private boolean beep; public TalkingClock(int interval, boolean beep) { this.interval = interval; this.beep = beep; } public void start(){ ActionListener listener =new TimePrinter(); Timer t=new Timer(interval,listener); t.start(); } public class TimePrinter implements ActionListener{ public void actionPerfermed(ActionEvent event){ System.out.println("At the tone,the time is "+new Date()); if(beep) Toolkit.getDefaultToolkit().beep(); } } }
内部类构造失败
Error:(29, 12) java: innerClass.TalkingClock.TimePrinter不是抽象的, 并且未覆盖java.awt.event.ActionListener中的抽象方法actionPerformed(java.awt.event.ActionEvent)