107054600
003008529
000000070
004905100
800700900
012003000
700000006
200609004
036010000
ファイルには、このように数独パズルが保存されます。
これらのパズルを 2 次元の int 配列と 2 次元の Jlabel 配列の両方に読み取れるようにする必要があります。
Int 配列のみを読み込む場合に機能します。ただし、j ラベルのアイコン値を for ループによって処理されている現在の番号に割り当てようとすると、次のコンパイラ エラーが発生します。
コンストラクタ javax.swing.JLabel(int) は未定義です
どうしてこれなの?
関連するコードは次のとおりです。
JLabel[][] gridLabels = new JLabel[9][9];
int [][] grid = new int [9][9]; // Game Array
try {
String fileName1 = new Scanner(new File("./temp.txt")).useDelimiter("\\Z").next();
Scanner fin;
fin = new Scanner( new File(fileName1));
//Reads in the puzzle from a temporary text file
for(int row=0; row<9; row++)
{
String line = fin.next();
for(int col=0; col<9; col++)
{ grid[row][col] = line.charAt(col)-'0';
gridLabels[row][col] = new JLabel(line.charAt(col)-'0'); //PROBLEM HERE//
}
}
}
catch (FileNotFoundException exception)
{System.out.println("Incorrect Selection"); // Catches incorrect selection
}
catch (NoSuchElementException exception)
{System.out.println("No Such Element");
}