Reputation: 5
I wanted to write the code for the timer, but I guess I wrote something wrong or didn’t write it at all.
I searched for the same problem here. Most of the answers were about a right import, but it didn’t help as my import is right, in my opinion
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."
I would appreciate your help. Thanks in advance!
Upvotes: 0
Views: 422
Reputation: 271
Review the import statement as below,
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
}
});
}
Upvotes: 1