我创建了一个程序来读取文件并计算值并在每次单击按钮(执行按钮)时将总计打印到文本字段,我将此文本字段附加到JFrame中。
我的代码运行良好但我的问题是每次关闭JFrame并再次单击该按钮时,值是我的JTextField保留,并且在我第二次单击执行按钮时,总计将乘以2。谁能帮我?我想在每次关闭JFrame时刷新我的JTextfield。这是我使用的代码。谢谢!
ArrayList<String>totalResult= newArrayList<String>();
try
{
FileInputStream f1 = new FileInputStream(AddressFile);
DataInputStream in1 = new DataInputStream(f1);
BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
String lines;
while((lines = br1.readLIne())!=null)
{
if(line.length()!=0 && (lines.charAt(0)!='#'))
{
String[] employee = lines.split("\\s+");
totalResult.add(employee[2]);
}
}
for(String s : totalResult)
{
vacationLeave = Double.parseDouble(s);
totalVacationLeave +=vacationLeave
}
try
{
while(!loopVacationLeave)
try
{
BigDecimal roundOff = new DigDecimal(totalVacationLeave).setScale(3,
RoundingMode.HALF_EVEN;)
totalVacationLeave = roundOff.doubleValue();
if(SUMMARY_MONITORING_PERSONNEL.employeeVL7.getText()!=null)
SUMMARY_MONITORING_PERSONNEL.employeeVL7.setText("" +
totalVacationLeave);
loopVacationLeave = true;
}
catch(Exception e)
{
}
}
catch(Exception e)
{
}
in1.close();
}
catch(Exception e)
{
SUMMARY_MONITORING_PERSONNEL.employeeVL7.setText("No File");
}
答案 0 :(得分:2)
EXIT_ON_CLOSE
,DO_NOTHING_ON_CLOSE
,HIDE_ON_CLOSE
或DISPOSE_ON_CLOSE
,如果您要退出或处置,则无法执行此操作。
如果你想保存你的框架状态以便隐藏它,(当用户单击顶部的X
按钮时)它将只对屏幕不可见,并且可以进行任何修改而不是你需要显示它。
或强>
您可以手动frame.setVisible(true|false);