我通过生成一些变量
String[] StoreValueFromTable = new String[5];
String[] ColumName = new String[5];
for(int Count=0;Count<5;Count++){
StoreValueFromTable[Count] = "QueryTechnica"+Count;
ColumName[Count] = "QT"+Count;
System.out.println(StoreValueFromTable[Count]+", "+ColumName[Count]);
}
我正在尝试使JTextField[] Fiels[Count] = new JTextField();
出错。我不确定,有没有一种方法可以使它动态。。
您可以这样做:
final int TEXTFIELDS_COUNT = 5;
// Create an array of 5 JTextFields
JTextField[] fields = new JTextField[TEXTFIELDS_COUNT];
for(int count = 0; count< TEXTFIELDS_COUNT; count++){
// fields[count] represents a single JTextField
fields[count] = new JTextField();
// Do something with fields[count], like setting its text
// fields[count].setText("some text");
StoreValueFromTable[count] = "QueryTechnica"+count;
ColumName[count] = "QT"+count;
System.out.println(StoreValueFromTable[count]+", "+ColumName[count]);
}