我试图用java创建一个动态数独的gui,事情就是我似乎无法获得 如果有人可以帮助我或者建议更好的话,右侧面板中的文本字段 解决这个问题我会很高兴。问题是我只在最后一个面板中获取文本字段(在右边的按钮处)。在所有其他面板中,我没有得到任何文本字段,不知道为什么:P
class Sudoku extends JPanel{
private JTextField textfields[][];
private JPanel panels[][];
public Sudoku(int height, int weight, int dimension){
super();
panels = new JPanel[dimension][dimension];
textfields = new JTextField[dimension][dimension];
setLayout(new GridLayout());
setForeground(Color.black);
setBackground(Color.white);
for (int i = 0;i <= dimension-1;i++ ) {
for (int j = 0;j <= dimension-1;j++ ) {
textfields[i][j] = new JTextField(1);
textfields[i][j].setBackground(Color.YELLOW);
}
}
for (int i = 0;i <= weight;i++ ) {
for (int j = 0;j <= weight;j++ ) {
panels[i][j] = new JPanel(new GridLayout(weight, weight));
}
}
setLayout(new GridLayout(weight,weight,10,10));
setForeground(Color.BLACK);
for (int i = 0;i <= height-1 ;i++ ) {
for (int j = 0;j <= weight-1 ;j++ ) {
for (int k = 0;k <= height-1 ;k++ ) {
for (int l = 0;l <= weight-1 ;l++ ) {
textfields[l][k].setEditable(false);
panels[i][j].add(textfields[l][k]);
}
}
add(panels[i][j]);
}
}
}
}