/**
* This method returns tileNumber to SlidingPuzzle class to locate a PuzzleTile.
*
* @return tileNumber The number of PuzzleTile displays.
*/
public String getTileNumber(){
return tileNumber;
}
public PuzzleTile(int number) {
super();
if (number == 0) {
this.setBackground(Color.white);
}
else {
this.setBackground(Color.darkGray);
}
this.tileNumber = "" + number;
}
// You will need to provide more methods to interact with your
// main program.
}
比较明显了,Exception in thread "main"java.lang.ArrayIndexOutofBoundsException,数组越界,你所期望取的那个数组位置不存在,譬如你整个数组大小也就[2,2]你却取了[2,3]或[-1,x].
这种异常就不帮你找哪里出错了, 果断debug一下吧,不出几分钟你就会找到问题原因了。
public static int level=3;
public PuzzleTile[][] XueButtonArray= new PuzzleTile[level-1][level-1];
你定义了一个[2][2]的二维数组,
for(int i=0;i<level;i++)
循环的时候却有3个,当然数组下标越界