我正在尝试根据从文件输入的字长来创建一个JTextField数组。我似乎无法找到从String []转换为JTextField []的方法。
//Splits the word chosen from word list into an array
JTextField[] wordAmount = new JTextField[word.length()];//Creates a JtextField for each letter
String[] items = word.split("");
String temp;
for (int j = 0; j < items.length; j ++) {
temp = items[j];
wordAmount[j].setText(temp);
}
答案 0 :(得分:0)
在调用方法之前,需要初始化JTextField数组中的每个JTextField,因此在调用setText()方法之前添加此语句
wordAmount[j] = new JTextField();
所以将你的for循环更改为
for (int j = 1; j < items.length; j++) {
temp = items[j];
wordAmount[j] = new JTextField();
wordAmount[j].setText(temp);
}