[英]“Cannot resolve symbol” in some of the javax.swing.Timer methods in IntelliJ IDEA
I have been searching for a couple hours now and can't seem to find an answer on this. 我已经搜索了几个小时,似乎无法找到答案。
I import javax.swing.* so that i can use Timer in my program, but while Timer is imported and seem to be functioning, other methods that Timer has cannot be resolved by intellij and I get the following Errors : Errors picture enter image description here 我导入了javax.swing。*,以便可以在程序中使用Timer,但是在导入Timer并似乎可以正常工作的同时,intellij无法解决Timer已解决的其他方法,并且出现以下错误: 错误图片 输入图片描述这里
Here is my code: 这是我的代码:
` `
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();
}
` `
Note you are calling Timer class methods at Board class declaration level, not from within a Board class method. 请注意,您是在Board类声明级别而不是从Board类方法内部调用Timer类方法。 Those are illegal Java statements and the actual reason of the error messages.
这些是非法的Java语句以及错误消息的实际原因。 You should encapsulate those calls in a new Board class method -let's say initTimer()- and call this method when needed.
您应该将这些调用封装在一个新的Board类方法中-让我们说initTimer()-,并在需要时调用此方法。
On the other hand clockTimer variable declaration and initialization are ok. 另一方面,clockTimer变量的声明和初始化都可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.