[英]Why does the compiler tell me “actionPerformed method not implemented”?
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import javafx.event.ActionEvent;
public class hello {
public static void main(String[] args) {
TalkClock clock = new TalkClock();
clock.start(1000, true);
System.out.println("xxxx");
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
}
}
class TalkClock
{
public void start(int interval, boolean beep){
ActionListener listener = new ActionListener()
{
public void actionPerformed(ActionEvent event) {
System.out.println("At the tone, the time is " + new Date());
if (beep) Toolkit.getDefaultToolkit().beep();
}
};
Timer t = new Timer(interval, listener);
t.start();
}
}
I run it in my Mac.我在我的 Mac 上运行它。 The error is错误是
hello.java:24: error: <anonymous TalkClock$1> is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
{
^
1 error
You import the ActionEvent from JavaFX.您从 JavaFX 导入 ActionEvent。 You need to import the swing class.您需要导入 swing class。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.