我现在已经搜索了几个小时,似乎无法找到答案。
我导入 javax.swing.* 以便我可以在我的程序中使用 Timer,但是当 Timer 被导入并且似乎正在运行时,intellij 无法解决 Timer 的其他方法,我得到以下错误: 错误图片 输入图像描述这里
这是我的代码:
`
import java.util.Random;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.*;
public class Board
{
Random rn = new Random();
private SquareType[][] squares;
private int height;
private int width;
public Poly falling;
private int fallingX;
private int fallingY;
public Board(final int height, final int width) {
this.width = width;
this.height = height;
squares = new SquareType[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
squares[i][j] = SquareType.EMPTY;
}
}
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public SquareType whichSquareType(int height, int width) {
//Takes in two integers one for height and one for width and returns
// the SquareType of the particular cell
return squares[height][width];
}
public void randomizeBoard() {
SquareType[] myTypes = SquareType.values();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
squares[i][j] = myTypes[rn.nextInt(myTypes.length)];
}
}
}
public int getFallingX() {
return fallingX;
}
public int getFallingY() {
return fallingY;
}
public Poly getFalling() {
return falling;
}
final Action doOneStep = new AbstractAction()
{
public void actionPerformed(ActionEvent e) {
}
};
final Timer clockTimer = new Timer(500, doOneStep);
clockTimer.setCoalesce(true);
clockTimer.start();
}
`