Employee Management System Project In Java With Source Code
The Employee Management System Project In Java With Source Code is developed using Java Programming Language, this Employee Management System Java application stores all the employee’s information in a database.
This Employee Management System In Java is an application developed in Java GUI technology and the database used is SQLite.
An Employee Management System Project In Java Netbeans contains employee information like employee id, first name, surname, and age.
It is an easy-to-use application and has a user-friendly interface. This Project is totally built at the administrative end which means that only the admin has access rights to change or modify any records.
So this Employee Management System Java Code makes it a safe and reliable application to use.
By the way, I have here a list of Best Java Projects With Source Code For Beginners Free Download maybe this can help a lot.
This Java Code For Employee Management System main aim of developing this application was to reduce the errors that occur in the manual system. One can search the details easily by just entering the employee id.
In earlier systems, there was not such a facility to do so. All the details are stored in an SQLite database.
It is easy to update any employee details. All the employee records are integrated which makes it user-friendly and easy to use this Employee Payroll Management System Project In Java With Source Code.
List of Modules
- Employee Manager
- Allowance
- Deduction
- Search
- Update Salary
- Payment
This Source Code For Employee Management System In Java also includes a downloadable Employee Leave Management System Source Code In Java or Employee Management System Project In Java Source Code Download for free, just find the downloadable source code below and click to start downloading.
To start creating an Employee Management System Project In Java With Source Code, make sure that you have NetBeans IDE or any platform of Java installed on your computer.
About The Employee Management System In Java
Project Name: | Employee Management System |
Language/s Used: | JAVA |
Database: | MySQL |
Type: | Desktop Application |
Developer: | IT SOURCECODE |
Updates: | 0 |
Employee Management System Project In Java With Source Code: Steps on how to create the project
Time needed: 5 minutes
These are the steps on how to create an Employee Management System Project In Java With Source Code
- Step 1: Create a project.
First, open the file and then click “project” to create.
- Step 2: Create a project name.
Second, name your project.
- Step 3: Create JFrame.
Third, create a “JFrame” form.
- Step 4: Create a JFrame name.
Fourth, name your JFrame form.
- Step 5: Project Design.
Fifth, The actual design of the project.
The Code Given Below Is For Adding New Employee Module
package employee.payroll.system;
/**
*
* @author Hyrex
*/
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.imageio.ImageIO;
import javax.swing.*;
import net.proteanit.sql.DbUtils;
public class addEmployee extends javax.swing.JFrame {
Connection conn=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Staff_details
*/
public addEmployee() {
initComponents();
conn=db.java_db();
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
setLocation(size.width/2 - getWidth()/2,
size.height/2 - getHeight()/2);
currentDate();
txt_emp.setText(String.valueOf(Emp.empId).toString());
}
public void currentDate (){
Calendar cal =new GregorianCalendar();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
lbl_date.setText((month+1)+"/"+day+"/"+year);
//Time
int second = cal.get(Calendar.SECOND);
int minute = cal.get(Calendar.MINUTE);
int hour = cal.get(Calendar.HOUR);
lbl_time.setText(hour+":"+(minute)+":"+second);
}
/**
* 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() {
jMenuBar2 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jPanel3 = new javax.swing.JPanel();
jLabel7 = new javax.swing.JLabel();
txt_tel = new javax.swing.JTextField();
txt_email = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
r_male = new javax.swing.JRadioButton();
r_female = new javax.swing.JRadioButton();
txt_dob = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txt_surname = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
txt_firstname = new javax.swing.JTextField();
txt_id = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jDesktopPane1 = new javax.swing.JDesktopPane();
img = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
txt_pc = new javax.swing.JTextField();
txt_apt = new javax.swing.JTextField();
txt_add2 = new javax.swing.JTextField();
txt_address = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
txt_dep = new javax.swing.JTextField();
txt_desig = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
jLabel17 = new javax.swing.JLabel();
txt_status = new javax.swing.JTextField();
txt_doj = new javax.swing.JTextField();
jLabel12 = new javax.swing.JLabel();
jLabel18 = new javax.swing.JLabel();
txt_salary = new javax.swing.JTextField();
cmd_save = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
txt_job = new javax.swing.JTextField();
jLabel20 = new javax.swing.JLabel();
txt_emp = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
File = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
lbl_date = new javax.swing.JMenu();
lbl_time = new javax.swing.JMenu();
jMenu1.setText("File");
jMenuBar2.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar2.add(jMenu2);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Employee Details", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Adobe Arabic", 1, 14))); // NOI18N
jLabel7.setText("Contact :");
jLabel6.setText("Email :");
jLabel11.setText("Gender:");
r_male.setText("Male");
r_male.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
r_maleActionPerformed(evt);
}
});
r_female.setText("Female");
r_female.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
r_femaleActionPerformed(evt);
}
});
jLabel3.setText("Date of Birth :");
jLabel2.setText("Surname :");
jLabel1.setText("First name :");
txt_firstname.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_firstnameActionPerformed(evt);
}
});
txt_id.setEditable(false);
jLabel5.setText("Employee id :");
jDesktopPane1.setLayer(img, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
jDesktopPane1.setLayout(jDesktopPane1Layout);
jDesktopPane1Layout.setHorizontalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(img, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
.addContainerGap())
);
jDesktopPane1Layout.setVerticalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(img, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
.addContainerGap())
);
jLabel8.setText("Address Line 1 :");
jLabel14.setText("Address Line 2 :");
jLabel15.setText("Apt./House No :");
jLabel16.setText("Post Code :");
txt_apt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_aptActionPerformed(evt);
}
});
jLabel9.setText("Department :");
jLabel13.setText("Designation :");
jLabel17.setText("Status :");
jLabel12.setText("Basic Salary :");
jLabel18.setText("Date Hired :");
txt_salary.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_salaryActionPerformed(evt);
}
});
cmd_save.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/Save-icon.png"))); // NOI18N
cmd_save.setText("Add Record");
cmd_save.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd_saveActionPerformed(evt);
}
});
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/erase-128.png"))); // NOI18N
jButton1.setText("Clear");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
txt_job.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_jobActionPerformed(evt);
}
});
jLabel20.setText("Job Title :");
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel11))
.addGap(81, 81, 81)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txt_email, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_tel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(r_male)
.addGap(4, 4, 4)
.addComponent(r_female))))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel5))
.addGap(58, 58, 58)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txt_surname, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_id, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_firstname)
.addComponent(txt_dob, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel20)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txt_job, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel18)
.addComponent(jLabel12)
.addComponent(jLabel13)
.addComponent(jLabel9))
.addGap(28, 28, 28)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_doj)
.addComponent(txt_salary)
.addComponent(txt_status)
.addComponent(txt_dep)
.addComponent(txt_desig, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jLabel17))
.addGap(18, 18, 18)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel14)
.addComponent(jLabel15)
.addComponent(jLabel16)
.addComponent(jLabel8))
.addGap(48, 48, 48)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txt_pc, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_add2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_address, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_apt, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(cmd_save, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(33, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(txt_dep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_desig, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel13))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel17)
.addComponent(txt_status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel18)
.addComponent(txt_doj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5)
.addComponent(txt_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(7, 7, 7)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txt_firstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(txt_surname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(txt_dob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel12)
.addComponent(txt_salary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)
.addComponent(r_male)
.addComponent(r_female))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel20)
.addComponent(txt_job, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_tel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd_save, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_address, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_add2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel14))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_apt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel15))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel16)
.addComponent(txt_pc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(141, 141, 141))
);
txt_emp.setText("emp");
jLabel10.setText("Logged in As :");
File.setText("File");
jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/attach.png"))); // NOI18N
jMenuItem1.setText("Attach Image");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
File.add(jMenuItem1);
jMenuBar1.add(File);
lbl_date.setText("Date");
jMenuBar1.add(lbl_date);
lbl_time.setText("Time");
jMenuBar1.add(lbl_time);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_emp))
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(36, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
.addComponent(txt_emp))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 497, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28))
);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
filename =f.getAbsolutePath();
ImageIcon imageIcon = new ImageIcon(new ImageIcon(filename).getImage().getScaledInstance(img.getWidth(), img.getHeight(), Image.SCALE_DEFAULT));
img.setIcon(imageIcon);
try {
File image = new File(filename);
FileInputStream fis = new FileInputStream (image);
ByteArrayOutputStream bos= new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for(int readNum; (readNum=fis.read(buf))!=-1; ){
bos.write(buf,0,readNum);
}
person_image=bos.toByteArray();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
private void txt_jobActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txt_id.setText("");
txt_firstname.setText("");
txt_surname.setText("");
txt_tel.setText("");
txt_dob.setText("");
txt_email.setText("");
txt_address.setText("");
txt_dep.setText("");
txt_status.setText("");
txt_salary.setText("");
txt_add2.setText("");
txt_pc.setText("");
txt_desig.setText("");
txt_job.setText("");
txt_apt.setText("");
txt_doj.setText("");
img.setIcon(null);
}
private void cmd_saveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int p = JOptionPane.showConfirmDialog(null, "Are you sure you want to add record?","Add Record",JOptionPane.YES_NO_OPTION);
if(p==0){
try {
String sql ="insert into Staff_information "
+ "(first_name,surname,Dob,Email,"
+ "Telephone,Address,Department,"
+ "Image,Salary,Gender,Address2,"
+ "Post_code, Designation,Status,job_title,Apartment,Date_hired) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_firstname.getText());
pst.setString(2,txt_surname.getText());
pst.setString(3,txt_dob.getText());
pst.setString(4,txt_email.getText());
pst.setString(5,txt_tel.getText());
pst.setString(6,txt_address.getText());
pst.setString(7,txt_dep.getText());
pst.setBytes(8,person_image);
pst.setString(9,txt_salary.getText());
pst.setString(10,gender);
pst.setString(11,txt_add2.getText());
pst.setString(12,txt_pc.getText());
pst.setString(13,txt_desig.getText());
pst.setString(14,txt_status.getText());
pst.setString(15,txt_job.getText());
pst.setString(16,txt_apt.getText());
pst.setString(17,txt_doj.getText());
pst.execute();
JOptionPane.showMessageDialog(null,"Data is saved successfully");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
try {
String sq ="select * from Staff_information where (id) NOT IN (select emp_id from Users)";
pst=conn.prepareStatement(sq);
rs=pst.executeQuery();
while(rs.next()){
String add1 =rs.getString("id");
String add2 =rs.getString("first_name");
String add3 =rs.getString("Dob");
String result =add3.replace("/" ,"");
String add4 =rs.getString("Department");
String sql ="insert into Users (division,username,password,emp_id) values ('"+add4+"','"+add2+"','"+result+"','"+add1+"') ";
pst=conn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(null,"User account has been created successfully: " +" Username: "+add2+ " Password: "+result);
}
}catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
Date currentDate = GregorianCalendar.getInstance().getTime();
DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);
String value0 = timeString;
String value1 = dateString;
String val = txt_emp.getText().toString();
try{
String reg= "insert into Audit (emp_id, date, status) values ('"+val+"','"+value0+" / "+value1+"','Added Record')";
pst=conn.prepareStatement(reg);
pst.execute();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
}
}
}
private void txt_salaryActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_aptActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_firstnameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void r_femaleActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
gender ="Female";
r_female.setSelected(true);
r_male.setSelected(false);
}
private void r_maleActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
gender ="Male";
r_male.setSelected(true);
r_female.setSelected(false);
}
In this module which is adding a new employee module.
The Code Given Below Is For The Allowance Module
package employee.payroll.system;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.imageio.ImageIO;
import javax.swing.*;
import net.proteanit.sql.DbUtils;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Hyrex
*/
public class Allowance extends javax.swing.JFrame {
Connection conn=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Allowance
*/
public Allowance() {
initComponents();
conn=db.java_db();
Update_table();
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
setLocation(size.width/2 - getWidth()/2,
size.height/2 - getHeight()/2);
txt_emp.setText(String.valueOf(Emp.empId).toString());
}
private void Update_table() {
try{
String sql ="select * from allowance";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
table_allowance.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
txt_empid = new javax.swing.JTextField();
txt_dob = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
txt_salary = new javax.swing.JTextField();
txt_dept = new javax.swing.JTextField();
txt_surname = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
txt_firstname = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
txt_med = new javax.swing.JTextField();
txt_bonus = new javax.swing.JTextField();
txt_other = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
txt_hw = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
txt_total_overtime = new javax.swing.JTextField();
txt_per = new javax.swing.JTextField();
jLabel15 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jLabel14 = new javax.swing.JLabel();
txt_search = new javax.swing.JTextField();
txt_cal = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
table_allowance = new javax.swing.JTable();
jLabel10 = new javax.swing.JLabel();
lbl_total = new javax.swing.JLabel();
txt_emp = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
txt_empid.setEditable(false);
txt_dob.setEditable(false);
jLabel3.setText("Date of Birth :");
jLabel2.setText("Surname :");
jLabel1.setText("First name :");
jLabel5.setText("Employee id :");
jLabel12.setText("Basic Salary :");
txt_salary.setEditable(false);
txt_salary.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_salaryActionPerformed(evt);
}
});
txt_dept.setEditable(false);
txt_surname.setEditable(false);
jLabel9.setText("Department :");
txt_firstname.setEditable(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txt_dept, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel5)
.addComponent(jLabel12))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_salary, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_firstname)
.addComponent(txt_empid)
.addComponent(txt_surname)
.addComponent(txt_dob, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(txt_empid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(4, 4, 4)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txt_firstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txt_surname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(9, 9, 9)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(txt_dob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_salary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(txt_dept, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(23, Short.MAX_VALUE))
);
txt_med.setText("0");
txt_med.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_medActionPerformed(evt);
}
});
txt_bonus.setText("0");
txt_other.setText("0");
jLabel6.setText("Medical :");
jLabel7.setText("Bouns :");
jLabel8.setText("Other :");
jLabel13.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
jLabel13.setText("Please enter the amounts");
txt_hw.setText("0");
jLabel4.setText("Overtime :");
txt_total_overtime.setEditable(false);
txt_total_overtime.setText("0");
txt_total_overtime.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_total_overtimeActionPerformed(evt);
}
});
txt_per.setEditable(false);
txt_per.setText("0");
jLabel15.setText("Total Overtime:");
jLabel11.setText("Rate Per Hour :");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8))
.addGap(43, 43, 43)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_med, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
.addComponent(txt_bonus)
.addComponent(txt_other)
.addComponent(txt_hw, javax.swing.GroupLayout.Alignment.TRAILING))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txt_total_overtime))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txt_per)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(206, Short.MAX_VALUE)
.addComponent(jLabel13)
.addGap(114, 114, 114))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel13)
.addGap(26, 26, 26)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txt_hw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_med, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel15)
.addComponent(txt_total_overtime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(txt_per, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(txt_bonus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_other, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addGap(40, 40, 40))
);
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/Save-icon.png"))); // NOI18N
jButton2.setText("Save");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Adobe Arabic", 1, 14))); // NOI18N
jLabel14.setText("Employee ID:");
txt_search.addContainerListener(new java.awt.event.ContainerAdapter() {
public void componentRemoved(java.awt.event.ContainerEvent evt) {
txt_searchComponentRemoved(evt);
}
});
txt_search.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_searchActionPerformed(evt);
}
});
txt_search.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txt_searchKeyReleased(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel14)
.addGap(18, 18, 18)
.addComponent(txt_search)
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_search, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel14))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
txt_cal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/Calculate.png"))); // NOI18N
txt_cal.setText("Calculate");
txt_cal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_calActionPerformed(evt);
}
});
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/erase-128.png"))); // NOI18N
jButton1.setText("Clear");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
table_allowance.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(table_allowance);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel10.setText("Total Amount :");
lbl_total.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
lbl_total.setText("0.00");
lbl_total.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
lbl_totalKeyTyped(evt);
}
});
txt_emp.setText("emp");
jLabel16.setText("Logged in As :");
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 543, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_total, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_cal, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel16)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_emp)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(lbl_total))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_cal, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
.addComponent(txt_emp)))
);
pack();
}// </editor-fold>
private void txt_medActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_searchComponentRemoved(java.awt.event.ContainerEvent evt) {
// TODO add your handling code here:
}
private void txt_searchActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_searchKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try{
String sql ="select * from Staff_information where id=? ";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_search.getText());
rs=pst.executeQuery();
String add1 =rs.getString("id");
txt_empid.setText(add1);
String add2 =rs.getString("first_name");
txt_firstname.setText(add2);
String add3 =rs.getString("surname");
txt_surname.setText(add3);
String add4 =rs.getString("Dob");
txt_dob.setText(add4);
String add5 =rs.getString("Salary");
txt_salary.setText(add5);
String add6 =rs.getString("Department");
txt_dept.setText(add6);
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
private void txt_salaryActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_calActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int salary = Integer.parseInt(txt_salary.getText());
int overtime = Integer.parseInt(txt_hw.getText());
double eight = 8;
double days = 25;
double dbop = 0;
double overtimeRate = 1.5;
//calculate the total hours of overtime
double Total_Overtime = overtime * overtimeRate;
String x = String.valueOf(Total_Overtime);
txt_total_overtime.setText(x);
//calculate overall overtime
dbop = salary /days/eight;
String s = String.valueOf(dbop);
txt_per.setText(s);
int med = Integer.parseInt(txt_med.getText());
int bonus = Integer.parseInt(txt_bonus.getText());
int other = Integer.parseInt(txt_other.getText());
int f = med+bonus+other;
double calc = Total_Overtime * dbop+f;
String c = String.valueOf(calc);
lbl_total.setText(c);
}
private void lbl_totalKeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txt_empid.setText("");
txt_firstname.setText("");
txt_surname.setText("");
txt_salary.setText("");
txt_dob.setText("");
txt_dept.setText("");
txt_med.setText("0");
txt_bonus.setText("0");
txt_other.setText("0");
txt_hw.setText("0");
txt_per.setText("0");
txt_total_overtime.setText("0");
lbl_total.setText("0.00");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (txt_empid.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Employee id Field is empty");
} else if (txt_firstname.getText().equals("")) {
JOptionPane.showMessageDialog(null, "First name Field is empty");
} else if (txt_surname.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Surname name Field is empty");
}
else if (txt_dob.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Date of Birth name Field is empty");
}
else if (txt_salary.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Salary Field is empty");
}
else if (txt_dept.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Department Field is empty");
}
else {
int p = JOptionPane.showConfirmDialog(null, "Are you sure you want to save record?","Add Record",JOptionPane.YES_NO_OPTION);
if(p==0){
try {
int value = Emp.empId;
String value1 = txt_salary.getText();
String value2 = txt_bonus.getText();
String value3 = txt_med.getText();
String value4 = txt_other.getText();
String value5 = txt_per.getText();
String value6 = txt_hw.getText();
String value7 = lbl_total.getText();
String value8 = txt_empid.getText();
String value9 = txt_firstname.getText();
String value10 = txt_surname.getText();
String sql= "insert into Allowance (created_by,emp_id,overtime,medical,bonus,other,salary,rate,total_allowance,firstname,surname) values ('"+value+"','"+value8+"','"+value6+"','"+value3+"','"+value2+"','"+value4+"','"+value1+"','"+value5+"','"+value7+"','"+value9+"','"+value10+"')";
pst=conn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(null, "Allowance Added");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
try{
Date currentDate = GregorianCalendar.getInstance().getTime();
DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);
String value0 = timeString;
String values = dateString;
String val = txt_emp.getText().toString();
String reg= "insert into Audit (emp_id, date, status) values ('"+val+"','"+value0+" / "+values+"','Updated Allowance Record')";
pst=conn.prepareStatement(reg);
pst.execute();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
}
Update_table();
}
private void txt_total_overtimeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
In this module which is the allowance module.
The Code Given Below Is For The Audit Details Module
package employee.payroll.system;
import javax.swing.JOptionPane;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.*;
import net.proteanit.sql.DbUtils;
/**
*
* @author Hyrex
*/
public class Audit_details extends javax.swing.JFrame {
Connection conn=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Audit_details
*/
public Audit_details() {
initComponents();
conn=db.java_db();
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
setLocation(size.width/2 - getWidth()/2,
size.height/2 - getHeight()/2);
Update_table3();
}
private void Update_table3() {
try{
String sql ="select * from Audit";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
tbl_3.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
/**
* 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() {
jPanel3 = new javax.swing.JPanel();
jScrollPane3 = new javax.swing.JScrollPane();
tbl_3 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
txt_search = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Login_Record", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Adobe Arabic", 1, 14))); // NOI18N
tbl_3.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane3.setViewportView(tbl_3);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/erase-128.png"))); // NOI18N
jButton1.setText("Reset");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 557, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton1)))
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addGap(6, 6, 6))
);
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Adobe Arabic", 1, 14))); // NOI18N
jLabel2.setText("Employee ID:");
txt_search.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txt_searchKeyReleased(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(txt_search, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_search, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void txt_searchKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try{
String sql ="select * from Audit where emp_id=? ";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_search.getText());
rs=pst.executeQuery();
tbl_3.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Update_table3();
txt_search.setText("");
}
This module is for the audit details module.
The Code Given Below Is For The Employee Deduction Module
package employee.payroll.system;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
/**
*
* @author Hyrex
*/
public class employeeDeductions extends javax.swing.JFrame {
Connection conn=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
/**
* Creates new form employeeDeductions
*/
public employeeDeductions() {
initComponents();
conn=db.java_db();
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
setLocation(size.width/2 - getWidth()/2,
size.height/2 - getHeight()/2);
lbl_emp.setText(String.valueOf(Emp.empId).toString());
}
/**
* 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() {
txt_id = new javax.swing.JTextField();
jPanel4 = new javax.swing.JPanel();
jLabel11 = new javax.swing.JLabel();
txt_search = new javax.swing.JTextField();
txt_firstname = new javax.swing.JTextField();
txt_surname = new javax.swing.JTextField();
txt_dob = new javax.swing.JTextField();
txt_dep = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jLabel19 = new javax.swing.JLabel();
jLabel18 = new javax.swing.JLabel();
jLabel17 = new javax.swing.JLabel();
txt_desig = new javax.swing.JTextField();
txt_status = new javax.swing.JTextField();
txt_doj = new javax.swing.JTextField();
txt_job = new javax.swing.JTextField();
txt_salary = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
txt_Save = new javax.swing.JButton();
txt_reason = new javax.swing.JTextField();
lbl_total = new javax.swing.JLabel();
lbl_emp = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
r_percentage = new javax.swing.JRadioButton();
jLabel12 = new javax.swing.JLabel();
r_amount2 = new javax.swing.JRadioButton();
txt_deduction = new javax.swing.JTextField();
txt_percentage = new javax.swing.JTextField();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
lbl_sal = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
txt_id.setEditable(false);
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Adobe Arabic", 1, 14))); // NOI18N
jLabel11.setText("Employee ID :");
txt_search.addContainerListener(new java.awt.event.ContainerAdapter() {
public void componentRemoved(java.awt.event.ContainerEvent evt) {
txt_searchComponentRemoved(evt);
}
});
txt_search.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_searchActionPerformed(evt);
}
});
txt_search.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txt_searchKeyReleased(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel11)
.addGap(18, 18, 18)
.addComponent(txt_search)
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_search, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
txt_firstname.setEditable(false);
txt_firstname.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_firstnameActionPerformed(evt);
}
});
txt_surname.setEditable(false);
txt_dob.setEditable(false);
txt_dep.setEditable(false);
jLabel13.setText("Basic Salary :");
jLabel20.setText("Job Title :");
jLabel19.setText("Date Hired :");
jLabel18.setText("Status :");
jLabel17.setText("Designation :");
txt_desig.setEditable(false);
txt_status.setEditable(false);
txt_doj.setEditable(false);
txt_job.setEditable(false);
txt_job.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_jobActionPerformed(evt);
}
});
txt_salary.setEditable(false);
txt_salary.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_salaryActionPerformed(evt);
}
});
jLabel9.setText("Department :");
jLabel8.setText("Date of Birth :");
jLabel7.setText("Surname :");
jLabel4.setText("First name :");
jLabel6.setText("Employee id :");
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/Calculate.png"))); // NOI18N
jButton1.setText("Calculate");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("Reason:");
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel5.setText("Total Deduction:");
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/erase-128.png"))); // NOI18N
jButton2.setText("Clear");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
txt_Save.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/Save-icon.png"))); // NOI18N
txt_Save.setText("Save");
txt_Save.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_SaveActionPerformed(evt);
}
});
lbl_total.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lbl_total.setText("0.00");
lbl_emp.setText("emp");
jLabel10.setText("Logged in As :");
r_percentage.setText("Percentage (%)");
r_percentage.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
r_percentageActionPerformed(evt);
}
});
jLabel12.setText("Update Salary by :");
r_amount2.setText("Amount");
r_amount2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
r_amount2ActionPerformed(evt);
}
});
txt_deduction.setEditable(false);
txt_deduction.setEnabled(false);
txt_percentage.setEditable(false);
txt_percentage.setEnabled(false);
jLabel14.setText("Percentage :");
jLabel15.setText("Amount:");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("Salary after deduction:");
lbl_sal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lbl_sal.setText("0.00");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(r_percentage)
.addGap(35, 35, 35)
.addComponent(r_amount2))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel14)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_percentage, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_reason, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel7)
.addComponent(jLabel4)
.addComponent(jLabel6)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txt_surname, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_firstname)
.addComponent(txt_dob, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_id)
.addComponent(txt_dep, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(53, 53, 53)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel18)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel19)
.addComponent(jLabel13)
.addComponent(jLabel17)
.addComponent(jLabel20))
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_doj)
.addComponent(txt_salary)
.addComponent(txt_status)
.addComponent(txt_desig)
.addComponent(txt_job, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(189, 189, 189)
.addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_deduction, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(lbl_total, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_sal, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addGroup(layout.createSequentialGroup()
.addGap(44, 44, 44)
.addComponent(txt_Save, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_emp)))
.addContainerGap(11, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6)
.addComponent(txt_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txt_firstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_desig, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel17))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel18)
.addComponent(txt_status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel19)
.addComponent(txt_doj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_surname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel20)
.addComponent(txt_job, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_dob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel13)
.addComponent(txt_salary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9)
.addComponent(txt_dep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(59, 59, 59)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(lbl_total))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(lbl_sal)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel12)
.addComponent(r_percentage)
.addComponent(r_amount2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_percentage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_deduction, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel14)
.addComponent(jLabel15))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txt_reason, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_Save, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
.addComponent(lbl_emp))
.addGap(7, 7, 7))
);
pack();
}// </editor-fold>
private void txt_searchComponentRemoved(java.awt.event.ContainerEvent evt) {
// TODO add your handling code here:
}
private void txt_searchActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_searchKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try{
String sql ="select * from Staff_information where id=? ";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_search.getText());
rs=pst.executeQuery();
String add1 =rs.getString("id");
txt_id.setText(add1);
String add2 =rs.getString("first_name");
txt_firstname.setText(add2);
String add3 =rs.getString("surname");
txt_surname.setText(add3);
String add4 =rs.getString("Dob");
txt_dob.setText(add4);
String add5 =rs.getString("Department");
txt_dep.setText(add5);
String add7 =rs.getString("Salary");
txt_salary.setText(add7);
String add8 =rs.getString("Status");
txt_status.setText(add8);
String add9 =rs.getString("Date_hired");
txt_doj.setText(add9);
String add10 =rs.getString("job_title");
txt_job.setText(add10);
String add17 =rs.getString("Designation");
txt_desig.setText(add17);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "No Data");
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
private void txt_firstnameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_jobActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_salaryActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_SaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int p = JOptionPane.showConfirmDialog(null, "Are you sure you want to add record?","Add Record",JOptionPane.YES_NO_OPTION);
if(p==0){
String value3 = lbl_emp.getText();
try {
String sql ="insert into Deductions (firstname,surname,salary,deduction_amount,deduction_reason,emp_id,made_by) values (?,?,?,?,?,?,'"+value3+"')";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_firstname.getText());
pst.setString(2,txt_surname.getText());
pst.setString(3,txt_salary.getText());
pst.setString(4,lbl_total.getText());
pst.setString(5,txt_reason.getText());
pst.setString(6,txt_id.getText());
pst.execute();
JOptionPane.showMessageDialog(null,"Data is saved successfully");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
try{
Date currentDate = GregorianCalendar.getInstance().getTime();
DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);
String value0 = timeString;
String values = dateString;
String val = lbl_emp.getText().toString();
String reg= "insert into Audit (emp_id, date, status) values ('"+val+"','"+value0+" / "+values+"','Updated Deduction Record')";
pst=conn.prepareStatement(reg);
pst.execute();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int salary = Integer.parseInt(txt_salary.getText());
if(r_percentage.isSelected()== true){
int percentage = Integer.parseInt(txt_percentage.getText());
//calculate the total hours of overtime
int total_percentage_deduction = salary /100 * percentage;
String x = String.valueOf(total_percentage_deduction);
int sal = salary - total_percentage_deduction;
lbl_total.setText(x);
lbl_sal.setText(String.valueOf(sal));
}
if(r_amount2.isSelected()== true){
int deduction = Integer.parseInt(txt_deduction.getText());
//calculate the total hours of overtime
int total_amount_deduction = salary - deduction;
String s = String.valueOf(total_amount_deduction);
lbl_sal.setText(s);
lbl_total.setText(String.valueOf(deduction));
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txt_id.setText("");
txt_firstname.setText("");
txt_surname.setText("");
txt_dob.setText("");
txt_dep.setText("");
txt_status.setText("");
txt_salary.setText("");
txt_desig.setText("");
txt_job.setText("");
txt_doj.setText("");
lbl_total.setText("0.00");
txt_percentage.setText("");
txt_deduction.setText("");
txt_reason.setText("");
txt_search.setText("");
lbl_sal.setText("0.00");
}
private void r_percentageActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
r_percentage.setSelected(true);
r_amount2.setSelected(false);
//r_amount.setEnabled(false);
txt_deduction.setEnabled(false);
txt_percentage.setEditable(true);
txt_percentage.setEnabled(true);
txt_deduction.setText("");
}
private void r_amount2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
r_amount2.setSelected(true);
r_percentage.setSelected(false);
//r_percentage.setEnabled(false);
txt_percentage.setEnabled(false);
txt_deduction.setEditable(true);
txt_deduction.setEnabled(true);
txt_percentage.setText("");
}
This module is the module for employee deduction.
The Code Given Below Is For The Login Module
package employee.payroll.system;
/**
*
* @author Hyrex
*/
import com.sun.glass.events.KeyEvent;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.swing.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class login extends javax.swing.JFrame {
Connection conn=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Login_jframe
*/
public login() {
initComponents();
conn=db.java_db();
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
setLocation(size.width/2 - getWidth()/2,
size.height/2 - getHeight()/2);
currentDate();
}
public void currentDate (){
Calendar cal =new GregorianCalendar();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
txt_date.setText((month+1)+"/"+day+"/"+year);
int second = cal.get(Calendar.SECOND);
int minute = cal.get(Calendar.MINUTE);
int hour = cal.get(Calendar.HOUR);
lbl_time.setText(hour+":"+(minute)+":"+second);
}
/**
* 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() {
jMenuItem1 = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
jPopupMenu1 = new javax.swing.JPopupMenu();
jPanel2 = new javax.swing.JPanel();
cmd_Login = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txt_username = new javax.swing.JTextField();
txt_password = new javax.swing.JPasswordField();
txt_combo = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu2 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
txt_date = new javax.swing.JMenu();
lbl_time = new javax.swing.JMenu();
jMenuItem1.setText("jMenuItem1");
jMenu1.setText("jMenu1");
jRadioButtonMenuItem1.setSelected(true);
jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jPanel2.setLayout(null);
cmd_Login.setBackground(new java.awt.Color(0, 153, 204));
cmd_Login.setText("Login");
cmd_Login.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd_LoginActionPerformed(evt);
}
});
cmd_Login.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
cmd_LoginKeyPressed(evt);
}
});
jPanel2.add(cmd_Login);
cmd_Login.setBounds(160, 470, 70, 30);
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Username:");
jPanel2.add(jLabel1);
jLabel1.setBounds(10, 360, 70, 14);
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Password:");
jPanel2.add(jLabel2);
jLabel2.setBounds(10, 400, 70, 14);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("Please enter your username and password");
jPanel2.add(jLabel6);
jLabel6.setBounds(10, 320, 241, 14);
jPanel2.add(txt_username);
txt_username.setBounds(100, 350, 132, 30);
txt_password.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_passwordActionPerformed(evt);
}
});
txt_password.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txt_passwordKeyPressed(evt);
}
});
jPanel2.add(txt_password);
txt_password.setBounds(100, 390, 132, 30);
txt_combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Admin", "Sales" }));
txt_combo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_comboActionPerformed(evt);
}
});
jPanel2.add(txt_combo);
txt_combo.setBounds(100, 430, 130, 30);
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Select Position:");
jPanel2.add(jLabel3);
jLabel3.setBounds(10, 440, 100, 14);
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/image-4.png"))); // NOI18N
jPanel2.add(jLabel4);
jLabel4.setBounds(0, 100, 790, 410);
jPanel3.setBackground(new java.awt.Color(0, 153, 204));
jLabel5.setFont(new java.awt.Font("Impact", 1, 36)); // NOI18N
jLabel5.setText("EMPLOYEE MANAGEMENT SYSTEM USING JAVA");
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel7.setText("By: ITSOURCECODE.COM");
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap(631, Short.MAX_VALUE)
.addComponent(jLabel7)
.addContainerGap())
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 712, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap(25, Short.MAX_VALUE)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel7)
.addGap(7, 7, 7))
);
jPanel2.add(jPanel3);
jPanel3.setBounds(0, 0, 790, 103);
jMenu2.setText("File");
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/employee/payroll/system/Images/Exit.png"))); // NOI18N
jMenuItem2.setText("Exit");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
jMenuBar1.add(jMenu3);
txt_date.setText("Date");
jMenuBar1.add(txt_date);
lbl_time.setText("Time");
jMenuBar1.add(lbl_time);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 788, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 509, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void txt_passwordActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cmd_LoginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (txt_username.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Username Field is empty");
} else if (txt_password.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Password Field is empty");
}else {
String sql = "select id,username,password,division from Users Where (username =? and password =? and division =?)";
//"select * from Employeeinfo where username=? and password=? and division=? and id=?";
try{
int count =0;
pst=conn.prepareStatement(sql);
pst.setString(1,txt_username.getText());
pst.setString(2,txt_password.getText());
pst.setString(3, txt_combo.getSelectedItem().toString());
rs=pst.executeQuery();
{
}
while(rs.next()){
int id = rs.getInt(1);
Emp.empId = id;
count =count+1;
}
String access=(txt_combo.getSelectedItem().toString());
if(access=="Admin") {
if(count==1){
JOptionPane.showMessageDialog(null,"Sucess" );
MainMenu j = new MainMenu();
j.setVisible(true);
this.dispose();
Date currentDate = GregorianCalendar.getInstance().getTime();
DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);
String value0 = timeString;
String values = dateString;
int value = Emp.empId;
String reg = "insert into Audit (emp_id,date,status) values ('"+value+"','"+value0+" / "+values+"','Logged in')";
pst=conn.prepareStatement(reg);
pst.execute();
this.dispose();
}
else if(count>1){
JOptionPane.showMessageDialog(null,"Duplicate Username or Password Access denied");
}
else{
JOptionPane.showMessageDialog(null,"Username and Password is not correct");
}
}
else if(access=="Sales"){
if(count ==1){
JOptionPane.showMessageDialog(null,"Sucess");
MainMenu j = new MainMenu();
j.setVisible (true);
Date currentDate = GregorianCalendar.getInstance().getTime();
DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);
String value0 = timeString;
String values = dateString;
int value = Emp.empId;
String reg = "insert into Audit (emp_id,date,status) values ('"+value+"','"+value0+" / "+values+"','Logged in')";
pst=conn.prepareStatement(reg);
pst.execute();
this.dispose();
}
else{
JOptionPane.showMessageDialog(null,"Username and Password is not correct");
}
}
} catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:#
System.exit(0);
}
private void cmd_LoginKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void txt_passwordKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
String sql = "select id,username,password,division from Users Where (username =? and password =? and division =?)";
//"select * from Employeeinfo where username=? and password=? and division=? and id=?";
try{
int count =0;
pst=conn.prepareStatement(sql);
pst.setString(1,txt_username.getText());
pst.setString(2,txt_password.getText());
pst.setString(3, txt_combo.getSelectedItem().toString());
rs=pst.executeQuery();
{
}
while(rs.next()){
int id = rs.getInt(1);
Emp.empId = id;
count =count+1;
}
String access=(txt_combo.getSelectedItem().toString());
if(access =="Admin") {
if(count==1){
JOptionPane.showMessageDialog(null,"Success" );
MainMenu j = new MainMenu();
j.setVisible(true);
this.dispose();
Date currentDate = GregorianCalendar.getInstance().getTime();
DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);
String value0 = timeString;
String values = dateString;
int value = Emp.empId;
String reg = "insert into Audit (emp_id,date,status) values ('"+value+"','"+value0+" / "+values+"','Logged in')";
pst=conn.prepareStatement(reg);
pst.execute();
this.dispose();
}
else if(count>1){
JOptionPane.showMessageDialog(null,"Duplicate Username or Password Access denied");
}
else{
JOptionPane.showMessageDialog(null,"Username and Password is not correct");
}
}
else if(access=="Sales"){
if(count ==1){
JOptionPane.showMessageDialog(null,"Success");
MainMenu j = new MainMenu();
j.setVisible (true);
Date currentDate = GregorianCalendar.getInstance().getTime();
DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);
String value0 = timeString;
String values = dateString;
int value = Emp.empId;
String reg = "insert into Audit (emp_id,date,status) values ('"+value+"','"+value0+" / "+values+"','Logged in')";
pst=conn.prepareStatement(reg);
pst.execute();
this.dispose();
}
else{
JOptionPane.showMessageDialog(null,"Username and Password is not correct");
}
}
} catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
}
}
private void txt_comboActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
This module is the module for the login system.
Downloadable Source Code Below
Summary
The System is built fully in Java and MySQL Database. It has a full-featured Graphical User Interface (GUI) with all the functionalities.
This article is a way to enhance and develop our skills and logic ideas which is important in practicing the Java programming language which is the most well-known and most usable programming language in many companies.
Related article below
- Best Java Projects With Source Code For Beginners Free Download
- Load data from MySQL database to Combo box Using Java
- Update Data using MySQL Database and Java with Netbeans IDE
- Join Two String Value using MySQL CONCAT Function in Java
- How to Load data from Mysql Database to Table Element Using Java
Inquiries
If you have any questions or suggestions about the Employee Management System Project In Java With Source Code, please feel free to leave a comment below.
What are the login credentials thank you, your work is inspiring
Can you tell me please, what are the login credentials?
Username = Admin
Password = pass
for more info contact us whatsapp 00252634582408
how to add images to employee