我有以下Java代码:
JFrame frame = new JFrame();
frame.setTitle("Sudoku");
frame.setLocationRelativeTo(null);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(ruudustik.peaRuudustik()); //returns JPanel with textfields inside
frame.setVisible(true);
ruudustik.peaRuudustik 功能:
public static JPanel peaRuudustik() {
JPanel panel = new JPanel();
for (int i = 0; i < 81; i++) {
final JTextField ruut = new JTextField();
ruut.setHorizontalAlignment(JTextField.CENTER);
ruut.setSize(30, 30);
ruut.setColumns(1);
ruut.setName(Integer.toString(i));
panel.add(ruut);
}
return panel;
}
我如何更改特定的文本字段值。每个文本字段都有唯一的名称。