简体   繁体   English

为什么编译器告诉我“actionPerformed 方法未实现”?

[英]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.

相关问题 为什么getGraphics在ActionPerformed方法中起作用? - Why getGraphics does work inside an ActionPerformed method? 为什么JFormattedTextField不支持actionPerformed - Why JFormattedTextField does not suppport actionPerformed 为什么Eclipse告诉我这是无效代码? - Why does Eclipse tell me that this is dead code? 为什么eclipse告诉我应该为静态方法引用ClassName :: staticMethod“以静态方式访问”? - Why does eclipse tell me I should “accessed in a static way” for static method reference ClassName::staticMethod? 单击JTextField是否会调用actionPerformed方法 - Does clicking on a JTextField call the actionPerformed method 为什么JTextField的setText在actionPerformed方法中不起作用? - Why is setText of JTextField not working in the actionPerformed method? 为什么我得到的Display不是抽象的并且没有覆盖Display中的抽象方法actionPerformed()? - Why am I getting the Display is not abstract and does not override abstract method actionPerformed() in Display? SearchEventListener 不是抽象的,不会覆盖抽象方法 actionPerformed - SearchEventListener is not abstract and does not override abstract method actionPerformed 有人能告诉我为什么这种方法会进入无限循环吗? - Can someone tell me why this method is going into an infinite loop? 为什么 IntelliJ 告诉我我的类从不返回 null? - Why does IntelliJ tell me that my class never returns null?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM