Sunday, October 18, 2015

Swing Payroll System in Java

A payroll program that I wrote in Java a long time ago that uses swing library for it graphical user interface design that will compute the salary of an employee in the company.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Program Listing

import javax.swing.*;
import java.awt.event.*;


public class payroll extends JFrame implements
ActionListener {

JTextField emp_name = new JTextField(15);
JTextField work     = new JTextField(15);
JTextField rate     = new JTextField(14);
JTextField days     = new JTextField(15);


JButton Compute = new JButton("Compute");
JButton Clear   = new JButton("Clear");


   JLabel emp_label2 = new JLabel();
    JLabel work_label2 = new JLabel();
    JLabel salary = new JLabel();
    JLabel report = new JLabel();

    double solve = 0.00;

public payroll() {

  super("Simple Payroll System");
  setSize(260,280);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  JPanel pane = new JPanel();

  JLabel emp_name_label = new JLabel(" Name         ");
  JLabel work_label     = new JLabel(" Position     ");
  JLabel rate_label     = new JLabel(" Rate Per Day ");
  JLabel days_label     = new JLabel(" No. of Days  ");

  pane.add(emp_name_label);
  pane.add(emp_name);

  pane.add(work_label);
  pane.add(work);


  pane.add(rate_label);
  pane.add(rate);
  pane.add(days_label);
  pane.add(days);

  pane.add(Compute);
  pane.add(Clear);

  Compute.addActionListener(this);
  Clear.addActionListener(this);
  Compute.setToolTipText("Click here to solve the salary.");
  Clear.setToolTipText("Click here to clear text fields.");

  pane.add(report);
  pane.add(emp_label2);
  pane.add(work_label2);
  pane.add(salary);
  add(pane);

  setVisible(true);
}

public void actionPerformed(ActionEvent e)
{

if(Compute==e.getSource())
{
                  String name= emp_name.getText();
                  String work2= work.getText();

             double emp_rate=Double.parseDouble(rate.getText());
             int emp_days = Integer.parseInt(days.getText());

             solve = (emp_rate * emp_days);

               report.setText(" === Salary Report === ");
                emp_label2.setText("Employee's Name  : "
                                    +name);
                work_label2.setText("Job Description : "
                                     +work2);
                salary.setText("   Employee's Salary : $ " +
                 String.format("%.2f",solve));

}

else if(Clear==e.getSource())
{
emp_name.setText("");
                work.setText("");
                rate.setText("");
                days.setText("");

                report.setText("");
                emp_label2.setText("");
                work_label2.setText("");
                salary.setText("");
}
}


public static void main(String[] args)
{
payroll employee = new payroll();
}
}

No comments:

Post a Comment