107054600
003008529
000000070
004905100
800700900
012003000
700000006
200609004
036010000
這些文件以這種方式存儲Sudoku拼圖。將填充數字值的文件分配給JLabels的二維陣列
我必須能夠將這些謎題讀入到2d int數組和2d Jlabel數組中。
它僅在讀入Int數組時纔有效。然而,當我嘗試分配與當前數第j標籤的圖標價值正處理for循環我得到這個編譯器錯誤:
The constructor javax.swing.JLabel(int) is undefined
這是爲什麼?
相關的代碼如下:
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");
}