Hello all,
I'm having a problem with displaying my entire list of employees from a text file.
Opening and storing are working fine, but displaying to my gui it only shows the last employee on the list.
I'll insert my code here:
[CODE=java] private void actionPerformed tbDisplayEmploy ees(javax.swing .event.Ancestor Event evt) {
// Code to Display Employee pay info:Need to open myData.txt or enter in new emps first:
try{
BufferedReader inputStream = null;
inputStream = new BufferedReader( new FileReader("myD ata.txt"));
if(inputStream == null){
JOptionPane.sho wMessageDialog( this, ("To display Employees you must open myData.txt" + "\n"
+ "or submit new employees."));
}
final double SS = .03;
final double FICA = .05;
for(int i=0;i<numString s;i++){
tmpEmp = new TEmployee();
tmpEmp = myCompany.getEm ployee(i);
String showLastName = tmpEmp.getEmpLa stName();
lblDisplayEmpLa stName.setText( showLastName);
double hours = Double.valueOf( tmpEmp.getEmpHo urs());
double payrate = Double.valueOf( tmpEmp.getEmpHr Rate());
double grosspay = (hours * payrate);
NumberFormat nf = NumberFormat.ge tCurrencyInstan ce(Locale.US);
nf.format(gross pay);
String showgrosspay = Double.toString (grosspay);
lblDisplayGross Pay.setText(sho wgrosspay);
//Calculate deductions
double totalSSdeduct =(grosspay * SS);
double totalFICAdeduct = (grosspay * FICA);
double totalDeduct = (totalSSdeduct + totalFICAdeduct );
nf.format(total Deduct);
nf.format(total SSdeduct);
String showSSdeduct = Double.toString (totalSSdeduct) ;
lblDisplayEmpSS Deductions.setT ext(showSSdeduc t);
nf.format(total FICAdeduct);
String showFICAdeduct = Double.toString (totalFICAdeduc t);
lblDisplayEmpFI CA.setText(show FICAdeduct);
double netpay = (grosspay - totalDeduct);
nf.format(netpa y);
String shownetpay = Double.toString (netpay);
lblDisplayNetPa y.setText(shown etpay);
}
} catch (FileNotFoundEx ception e) {
System.err.prin tln("FileStream sTest: " + e);
} catch (IOException e) {
System.err.prin tln("FileStream sTest: " + e);
}//end try/catch
}[/CODE]
I'd love to hear any ideas that may help.
I'm having a problem with displaying my entire list of employees from a text file.
Opening and storing are working fine, but displaying to my gui it only shows the last employee on the list.
I'll insert my code here:
[CODE=java] private void actionPerformed tbDisplayEmploy ees(javax.swing .event.Ancestor Event evt) {
// Code to Display Employee pay info:Need to open myData.txt or enter in new emps first:
try{
BufferedReader inputStream = null;
inputStream = new BufferedReader( new FileReader("myD ata.txt"));
if(inputStream == null){
JOptionPane.sho wMessageDialog( this, ("To display Employees you must open myData.txt" + "\n"
+ "or submit new employees."));
}
final double SS = .03;
final double FICA = .05;
for(int i=0;i<numString s;i++){
tmpEmp = new TEmployee();
tmpEmp = myCompany.getEm ployee(i);
String showLastName = tmpEmp.getEmpLa stName();
lblDisplayEmpLa stName.setText( showLastName);
double hours = Double.valueOf( tmpEmp.getEmpHo urs());
double payrate = Double.valueOf( tmpEmp.getEmpHr Rate());
double grosspay = (hours * payrate);
NumberFormat nf = NumberFormat.ge tCurrencyInstan ce(Locale.US);
nf.format(gross pay);
String showgrosspay = Double.toString (grosspay);
lblDisplayGross Pay.setText(sho wgrosspay);
//Calculate deductions
double totalSSdeduct =(grosspay * SS);
double totalFICAdeduct = (grosspay * FICA);
double totalDeduct = (totalSSdeduct + totalFICAdeduct );
nf.format(total Deduct);
nf.format(total SSdeduct);
String showSSdeduct = Double.toString (totalSSdeduct) ;
lblDisplayEmpSS Deductions.setT ext(showSSdeduc t);
nf.format(total FICAdeduct);
String showFICAdeduct = Double.toString (totalFICAdeduc t);
lblDisplayEmpFI CA.setText(show FICAdeduct);
double netpay = (grosspay - totalDeduct);
nf.format(netpa y);
String shownetpay = Double.toString (netpay);
lblDisplayNetPa y.setText(shown etpay);
}
} catch (FileNotFoundEx ception e) {
System.err.prin tln("FileStream sTest: " + e);
} catch (IOException e) {
System.err.prin tln("FileStream sTest: " + e);
}//end try/catch
}[/CODE]
I'd love to hear any ideas that may help.
Comment