Share on Google+Share on Google+

Abdullah Al- Mamun
PaySlip
1 Answer(s)      7 years ago
Posted in : Java Beginners
package dmm.ui;

import dmm.bean.Employee;
import dmm.bean.Employees;
import dmm.bean.FullTimeEmployee;
import dmm.bean.PartTimeEmployee;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
*
* @author Administrator
*/
public class PaySlip extends javax.swing.JInternalFrame {

Employees employees;
/** Creates new form PaySlip */
public PaySlip(Employees employees) {
this.employees=employees;
initComponents();
generateSlip();
}

public void generateSlip()
{
String user=JOptionPane.showInputDialog("Enter user name");
String password=JOptionPane.showInputDialog("Enter user password");



/*File file=new File("EmpInfo.ant");
FileInputStream fileInputStream=new FileInputStream(file);
ObjectInputStream objectInputStream=new ObjectInputStream(fileInputStream);

Employees employees=(Employees)objectInputStream.readObject();*/
//logic for password checking
//if wrong show error message
//else

Vector<Employee> allEmployees=employees.getEmployees();
txtPaySlip.setText("Pay slip\n");
txtPaySlip.append("ID\tName\tWorked Hour\tRate\tAnnual Salary\tEarnings\tTax\tAllowance\tPaymenty\n\n");
for(int i=0;i<allEmployees.size();i++)
{
Employee employee=allEmployees.get(i);
if(employee instanceof PartTimeEmployee)
{
PartTimeEmployee pte=(PartTimeEmployee)employee;

txtPaySlip.append(pte.getId()+"\t"+pte.getName()+"\t"+pte.getHoursWorked()+"\t"+pte.getHourlyRate()+"\tn/a"+"\t"+pte.earnings()+"\t"+Math.round(pte.tax())+"\t"+pte.Allowance()+"\t"+pte.payment()+"\n\n");
}
else if(employee instanceof FullTimeEmployee)
{
FullTimeEmployee fte=(FullTimeEmployee)employee;
txtPaySlip.append(fte.getId()+"\t"+fte.getName()+"\t n/a"+"\tn/a"+"\t"+fte.getAnnualSalary()+"\t"+fte.earnings()+"\t"+Math.round(fte.tax())+"\t"+fte.Allowance()+"\t"+fte.payment()+"\n\n");
}
}

}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
txtPaySlip = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
btnFundTransfer = new javax.swing.JButton();
btnTaxFile = new javax.swing.JButton();

txtPaySlip.setColumns(20);
txtPaySlip.setRows(5);
jScrollPane1.setViewportView(txtPaySlip);

getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

btnFundTransfer.setText("Create Fund Transfer File");
btnFundTransfer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFundTransferActionPerformed(evt);
}
});
jPanel1.add(btnFundTransfer);

btnTaxFile.setText("Create Tax File");
btnTaxFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTaxFileActionPerformed(evt);
}
});
jPanel1.add(btnTaxFile);

getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

pack();
}// </editor-fold>

private void btnTaxFileActionPerformed(java.awt.event.ActionEvent evt) {
String output="";
Vector<Employee> allEmployees=employees.getEmployees();
for(int i=0;i<allEmployees.size();i++) {
Employee employee=allEmployees.get(i);
if(employee instanceof FullTimeEmployee) {
FullTimeEmployee fte=(FullTimeEmployee)employee;
output+=fte.getId()+"\t"+fte.getName()+"\t"+Math.round(fte.tax())+"\n";
} else if(employee instanceof PartTimeEmployee) {
PartTimeEmployee pte=(PartTimeEmployee)employee;
output+=pte.getId()+"\t"+pte.getName()+"\t"+Math.round(pte.tax())+"\n";
}

}

try {
File file=new File("Tax.txt");
FileWriter fw=new FileWriter(file);
BufferedWriter bw=new BufferedWriter(fw);
bw.write(output);
bw.flush();
bw.close();
JOptionPane.showMessageDialog(this,"Tax file created");
} catch(IOException ioe) {
ioe.printStackTrace();
}
}

private void btnFundTransferActionPerformed(java.awt.event.ActionEvent evt) {
String output="";
Vector<Employee> allEmployees=employees.getEmployees();
for(int i=0;i<allEmployees.size();i++) {
Employee employee=allEmployees.get(i);
if(employee instanceof FullTimeEmployee) {
FullTimeEmployee fte=(FullTimeEmployee)employee;
output+=fte.getId()+"\t"+fte.getName()+"\t"+fte.getAccountHolder()+"\t"+fte.getAccountNo()+"\t"+fte.payment()+"\n";
} else if(employee instanceof PartTimeEmployee) {
PartTimeEmployee pte=(PartTimeEmployee)employee;
output+=pte.getId()+"\t"+pte.getName()+"\t"+pte.getAccountHolder()+"\t"+pte.getAccountNo()+"\t"+pte.payment()+"\n";
}

}

try {
File file=new File("Fund Transfer.txt");
FileWriter fw=new FileWriter(file);
BufferedWriter bw=new BufferedWriter(fw);
bw.write(output);
bw.flush();
bw.close();
JOptionPane.showMessageDialog(this,"Fund transfer file created");
} catch(IOException ioe) {
ioe.printStackTrace();
}
}


// Variables declaration - do not modify
private javax.swing.JButton btnFundTransfer;
private javax.swing.JButton btnTaxFile;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea txtPaySlip;
// End of variables declaration

}

Ads

View Answers

April 24, 2010 at 10:49 AM


Hi Friend,

Please clarify your problem.

Thanks









Related Tutorials/Questions & Answers:
PaySlip - Java Beginners
javax.swing.JOptionPane; /** * * @author Administrator */ public class PaySlip... new form PaySlip */ public PaySlip(Employees employees
printing in swing
printing in swing  How can i print payslip in swing
Advertisements
Needed jsp codes
Needed jsp codes   jsp code for employee payroll.producing a payslip of every employees monthly calculating the gross pay of a particular employee considering the income tax and producing a report which can be printed out
jsp code for employee payroll - JSP-Servlet
jsp code for employee payroll  jsp code for employee payroll. i need to generate the payslip with tax calucation and deductions,allwoance .how to calculate the employee tax using the jsp code  Hi Friend, Try
Vector object[]
Vector object[]  I want to create payslip in java public Vector createData() { Vector result = new Vector(); Vector rec = new Vector(); Object[] value = new Object[] {"Employee Name",f.ename.getSelectedItem
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads