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");
}