所以现在,我有一个 Brick.java,其中包含我想在 BreakoutCourt.java 中使用的 Levels 枚举,它包含在同一个包中,即(默认包)。
当我写 import Brick.level; 在 BreakoutCourt 中,我收到一条消息,指出无法解决导入砖。即使我写了 import static Brick.Level,我也会收到这条消息!
Brick.java 中包含的级别枚举如下所示:
public class Brick {
public static final int BWIDTH = 60;
public static final int BHEIGHT = 20;
private int xPos, yPos;
private Level brickLevel;
//This sets up the different levels of bricks.
enum Level{
LUNATIC (4, 40, Color.MAGENTA),
HARD (3, 30, Color.PINK),
MEDIUM (2, 20, Color.BLUE),
EASY (1, 10, Color.CYAN),
DEAD (0, 0, Color.WHITE);
private int hitpoints;
private int points;
private Color color;
Level(int hitpoints, int points, Color color){
this.hitpoints = hitpoints;
this.points = points;
this.color=color;
}
public int getPoints(){
return points;
}
public Color getColor(){
return color;
}
}
//rest of brick class goes under the enum
我在 BreakoutCourt 中这样使用它:
//Generates the bricks.
for(int i = 0; i < 8; ++i){
ArrayList<Brick> temp = new ArrayList<Brick>();
Level rowColor = null;
switch(i){
//There are two rows per type of brick.
case 0:
case 1:
rowColor = Level.EASY;
break;
case 2:
case 3:
rowColor = Level.HARD;
break;
case 4:
case 5:
rowColor = Level.LUNATIC;
break;
case 6:
case 7:
default:
rowColor = Level.MEDIUM;
break;
}
for(int j = 0; j < numBrick; j++){
Brick tempBrick = new Brick((j * Brick.BWIDTH), ((i+2) * Brick.BHEIGHT), rowColor);
temp.add(tempBrick);
}
我究竟做错了什么?感谢您的帮助!