<img id="rocket1" src="http://imageshack.com/a/img912/5645/0w5agB.png">
由5 jPanel
组成。我按jTextFields
动态添加jPanels
。并按addButton
检索动态添加的jPanel
值。代码saveButton
:
saveButton
我已将private void writefile(JPanel panel_name, PrintWriter file){
Component[] children = panel_name.getComponents();
for (Component sp : children) {
if (sp instanceof subPanel) {
Component[] spChildren = ((subPanel)sp).getComponents();
int count=1;
for (Component spChild : spChildren) {
if (spChild instanceof JTextField) {
String text = "";
if(count==1)
text=((JTextField)spChild).getText();
if(count==2)
text=((JTextField)spChild).getText();
if(count==4)
text=((JTextField)spChild).getText();
if(count==5)
text=((JTextField)spChild).getText();
if(count==3)
text=((JTextField)spChild).getText();
if(text.equals(null) || text.equals("")) {
}
else{
file.write(text);
}
}
}
}
}
输入到jTextFields,当我点击saveButton时,输出我得到的jTextField值为:1, 2, 4, 5, 3
。
即使我在1, 2, 3, 4, 5
之后写count==4
,无论如何输出我都按顺序排列。我想问一下如何在count==2
之后获得count==4
的价值?