动态添加文本字段值的操作

时间:2016-01-27 07:38:37

标签: java swing

<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的价值?

0 个答案:

没有答案