Reputation: 11
I have created a program that reads a file and tally the values and print the totals to a text field every time I click a button(execute button), I attached this text field in a JFrame.
My code works well but my problem is every time I close the JFrame and click the button again the value is my JTextField is retained, and on my second click of the execute button the totals will multiply by two. Can any one help me? I want to refresh the my JTextfield every time I close my JFrame. Here is the code I used. Thanks!
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");
}
Upvotes: 0
Views: 372
Reputation: 1976
What are you doing? show. EXIT_ON_CLOSE
, DO_NOTHING_ON_CLOSE
, HIDE_ON_CLOSE
or DISPOSE_ON_CLOSE
, If you are exiting or disposing off you can not do it.
IF you want to save the state of your frame so HIDE it, (When user click X
button at top) it will only not visible to screen and any modification can be done and than you need SHOW it.
OR
you can do manually frame.setVisible(true|false);
Upvotes: 2