java - 如何修复JAVA中的 "The constructor Timer(int, new ActionListener(){}) is undefined"错误?

标签 java timer

我想写定时器的代码,但我猜我写错了,或者根本就没有写。

我在这里搜索了同样的问题。大多数答案都是关于正确的导入,但这并没有帮助,因为我认为我的导入是正确的

 import javax.swing.Timer;

 timer = new Timer(delay, new ActionListener()
             {
                @Override
                public void actionPerformed(ActionEvent e) 
                {
                    update();
                    repaint();  
                }
            });

ERROR MESSAGE: "The constructor Timer(int, new ActionListener(){}) is undefined."

非常感谢您的帮助。提前致谢!

最佳答案

查看如下导入语句,

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class Main {
    public static void main(String[] arg) {

        int delay =1000;
        Timer timer = new Timer(delay , new ActionListener(){
           @Override
           public void actionPerformed(ActionEvent e) 
           {
               update();
               repaint();  
           }

           private void repaint() {
             // Do repainttask          
           }

           private void update() {
              //  Do update task            
           }  

       });

    }

关于java - 如何修复JAVA中的 "The constructor Timer(int, new ActionListener(){}) is undefined"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58087270/

相关文章:

javascript - 遇到一些 setInterval + jQuery FadeIn/FadeOut 问题

java - Swing 计时器仅工作一次

java - Opengl如何在缩放投影矩阵的同时平移光标位置

java swing/awt组件绘制棋盘

java - 跨线程反射

java - Swing 计时器未按计划工作

java - 由 : java. lang.NoSuchMethodError : org. springframework.beans.MutablePropertyValues.get(Ljava/lang/String;)Ljava/lang/Object 引起

Java 应用程序在 Windows 关闭时挂起

ios - iOS 中的简单计时器

javascript - AngularJS 中的警报计时器值