我有計時器錯誤,我不知道錯誤位於代碼中的位置。定時器執行錯誤
錯誤:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: The constructor Timer(int, Player) is undefined The method start() is undefined for the type Timer
at Player.(Player.java:12)
at Game.main(Game.java:11)
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.util.Timer;
import javax.swing.*;
public class Player extends JPanel implements ActionListener{
Timer t = new Timer(5, this); // Error (LINE 12)
double x = 0; double velX = 2;
double y = 0; double velY = 2;
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
Ellipse2D circle = new Ellipse2D.Double(x,y,40,40);
g2.fill(circle);
t.start(); // error
}
public void actionPerformed(ActionEvent e){
x += velX;
y += velY;
repaint();
}
}