我创建了一个Sudoku板,并且创建了9个JPanel,每个包含9个JTextFields。我的问题是,我不知道如何从一个SPECIFIC面板获取来自JTextField的输入。从JPanels数组中的JTextField中的数组访问数据? -Sudoku
这是我如何创建每个JTextField和JPanel。我已经用另一种方法初始化了它们。
private JPanel panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9;
private JPanel[][] smallgrids = { {panel1, panel2, panel3}, {panel4, panel5, panel6}, {panel7, panel8, panel9} };
private JTextField cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9;
private JTextField[][] cells = { {cell1, cell2, cell3}, {cell4, cell5, cell6}, {cell7, cell8, cell9}};
这是我做过什么让每个JTextField中输入:
String input;
for(int x = 0; x < 3; x++){
for(int y = 0; y < 3; y++){
input = cells[x][y].getText();
cells[x][y].setText(input);
}
}
//this was my test to see if it would print the correct value
System.out.println(input[0][0]);
我的问题是,循环访问来自细胞的输入,而不指定它是哪个面板。我如何指定我从哪个面板访问输入?对不起,如果措辞有点混乱。如果需要,我可以发布我的所有代码。