我想写定时器的代码,但我猜我写错了,或者根本就没有写。
我在这里搜索了同样的问题。大多数答案都是关于正确的导入,但这并没有帮助,因为我认为我的导入是正确的
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/