You are on page 1of 19

Coding

Menu bar
Login
this.setvisible(false);

new emp1.setvisible(true);
Employee registration:
this.setvisible(false);

new Employeeregistration().setvisible(true);

Employee details:
this.setvisible(false);

new Employeedetails().setvisible(true);

Employee salary input:


this.setvisible(false);

new sallog().setvisible(true);

Employee salary details:


this.setvisible(false);

new salarylogin().setvisible(true);

Toolbar

-Previous page -Home

-Next page -About us

-Search

-Open registration form


T his window appears first while start of the application. It
grants permission to the user to access the application
depending on the fact that you enter correct password or not.
If you enter correct password ,the home page of application appears
which will give access to all other options for application while if you
enter wrong password ,a message will pop –up indicating wrong
password.
Login:

String pd=new String(pwd.getPassword());

if(pd.equals("one")){

this.setVisible(false);

new emp1().setVisible(true);

else{

JOptionPane.showMessageDialog(null,"Invalid Password");

Clear:
t1.setText("");

pwd.setText("");

Exit:
System.exit(0);
Coding:
Save:
try{

Class.forName("java.sql.Driver");

con=DriverManager.getConnection("jdbc:mysql://localhost/employee","root","deep");

stmt=con.createStatement();

String sql="select*from empinput";

rs=stmt.executeQuery(sql);

while(rs.next()){

String eid=txtid.getText();
String ename=txtname.getText();

String edepart=txtdepartment.getText();

String edate=txtdate.getText();

String eaddress=txtadd.getText();

String ecity=txtcity.getText();

String ephone=txtphone.getText();

String query="insert into


empinput(emp_id,emp_name,emp_depart,emp_add,emp_city,emp_phone,emp_date)
values('"+eid+"','"+ename+"','"+edepart+"','"+eaddress+"','"+ecity+"','"+ephone+"','"+edate
+"')";

JOptionPane.showMessageDialog(null, "Record Successfully inserted");

int rowsEffected=stmt.executeUpdate(query);

catch(Exception ex){

JOptionPane.showMessageDialog(this, ex);}

Back to main:
this.setVisible(false);

new emp1().setVisible(true);

Clear:
txtid.setText("");

txtname.setText("");

txtadd.setText("");

txtcity.setText("");

txtdepartment.setText("");

txtphone.setText("");

txtdate.setText("");
This window displays the details of all the employees which have been
entered into the application through the registration window. The
‘Display Details’ button displays all the details from which the user can
look out for required details.

Coding:
Display Details:
// Before writting the followng line, you should import the line:

// import javax.swing.table.*; at the top of your application

DefaultTableModel model = (DefaultTableModel) table1.getModel();

// Clear the existing table

int rows = model.getRowCount();

if (rows > 0) {
for (int i = 0; i < rows; i++) {

model.removeRow(0);

// SQL Query

String query = "SELECT * FROM empinput";

try {

// Connect to MySQL database

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","juhi");

// Create SQL statement and execute query.

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

// Iterate through the result and display on screen

while (rs.next()) {

String eid =rs.getString("emp_id");

String ename=rs.getString("emp_name");

String edepart=rs.getString("emp_depart");

String edate=rs.getString("emp_date");

String eadd=rs.getString("emp_add");

String ecity=rs.getString("emp_city");

String ephone=rs.getString("emp_phone");

System.out.println(eid + "|" + ename + "|" +edepart + "|" + edate + "|" + eadd + "|" + ecity
+ "|" + ephone);

model.addRow(new Object[] {eid, ename,edepart, edate, eadd, ecity, ephone});


}

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Back to main menu:


this.setVisible(false);

new emp1().setVisible(true);

Run mode:
When a user wants to access the employee salary input form, from safety and
security point of view he/she cannot directly access it .First of all a password
window appears ,if the user enters the correct password if and only if the
salary input form appears.

Coding

String pd=new String(pwd.getPassword());

if(pd.equals("sal")){

this.setVisible(false);

new salaryinput().setVisible(true);

else{

JOptionPane.showMessageDialog(null, "You have entered wrong password");

}
If you entered the correct password, the following form will appear.
Coding:
Calculate salary:
int ehra,eda,esal,ebasic,eit;

ehra=Integer.parseInt(hra.getText());

eda=Integer.parseInt(da.getText());

ebasic=Integer.parseInt(basic.getText());
eit=ebasic/10;

esal=(ebasic+ehra+eda)-eit;

it.setText(""+eit);

sal.setText(""+esal);

Save:
try{

Class.forName("java.sql.Driver");

con=DriverManager.getConnection("jdbc:mysql://localhost/employee","root","juhi");

stmt=con.createStatement();

String sql="select*from salary";

rs=stmt.executeQuery(sql);

while(rs.next()){

String emid=txtid.getText();

String ename=txtname.getText();

String edepart=txtdep.getText();

String ehra=hra.getText();

String eda=da.getText();

String ebasic=basic.getText();

String eit=it.getText();

String esal=sal.getText();

String query="insert into salary(emp_id,emp_name,emp_dept,hra,da,incometax,sal,basic)


values('"+emid+"','"+ename+"','"+edepart+"','"+ehra+"','"+eda+"','"+eit+"','"+esal+"','"+ebasic+"')";

int rowsEffected=stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null, "Record Successfully inserted");

catch(Exception ex){
JOptionPane.showMessageDialog(this, ex);}

Clear:
txtid.setText("");

txtname.setText("");

txtdep.setText("");

da.setText("");

hra.setText("");

basic.setText("");

sal.setText("");

it.setText("");

If any unknown person wants to access the salary input form who do not know the correct
password

He/she will get a message indicating wrong password and will not be able to access the form.

Since
salary
details are secret ,so anyone who wants to access the details has to enter password in a
password window.
If you enter the correct password, following window will appear .

Coding:
Display Details:
// Before writting the following line, you should import the line:

// import javax.swing.table.*; at the top of your application

DefaultTableModel model = (DefaultTableModel) saltable.getModel();

// Clear the existing table

int rows = model.getRowCount();

if (rows > 0) {

for (int i = 0; i < rows; i++) {

model.removeRow(0);

// SQL Query

String query = "SELECT * FROM salary";

try {

// Connect to MySQL database

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","juhi");

// Create SQL statement and execute query.

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

// Iterate through the result and display on screen

while (rs.next()) {

String eid =rs.getString("emp_id");

String ename=rs.getString("emp_name");

String edepart=rs.getString("emp_dept");

String ebasic=rs.getString("basic");
String ehra=rs.getString("hra");

String eda=rs.getString("da");

String eit=rs.getString("incometax");

String esal=rs.getString("sal");

System.out.println(eid + "|" + ename + "|" +edepart + "|" + ebasic + "|" + ehra + "|" + eda +
"|" + eit+"|"+esal);

model.addRow(new Object[] {eid, ename,edepart, ebasic, ehra, eda, eit,esal});

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Back to main menu:


this.setVisible(false);

new emp1().setVisible(true);

If you enter the wrong password following message will appear.


This window gives necessary details about the application.
Displays the details of various forms of the application so
that the user can understand the application better.

You might also like