0% found this document useful (0 votes)
38 views

Class Employee

The document defines classes for an employee management application including: - An Employee class to represent employee objects with ID, name, and salary attributes - A SearchPanel class to display employee details based on ID - An AddPanel class to add new employees by collecting input fields - A Main class to run the application with buttons to search, add, and view all employees displayed in a table.

Uploaded by

swapnilharal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Class Employee

The document defines classes for an employee management application including: - An Employee class to represent employee objects with ID, name, and salary attributes - A SearchPanel class to display employee details based on ID - An AddPanel class to add new employees by collecting input fields - A Main class to run the application with buttons to search, add, and view all employees displayed in a table.

Uploaded by

swapnilharal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Class Employee

public class Employee


{
private int empId;
private String empName;
private double empSalary;
public Employee(int empId, String empName, double empSalary) {
super();
this.empId = empId;
this.empName = empName;
this.empSalary = empSalary;
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public double getEmpSalary() {

return empSalary;
}
public void setEmpSalary(double empSalary) {
this.empSalary = empSalary;
}
@Override
public String toString() {
return "Employee [empId=" + empId + ", empName=" + empName
+ ", empSalary=" + empSalary + "]";
}

Class searchPanel :-import javax.swing.JPanel;


import javax.swing.JTextField;

import com.employee.Employee;

@SuppressWarnings("serial")
public class SearchPanel extends JPanel
{

private JTextField jid,jname,jsalary;


public SearchPanel(Employee e[],int id)
{

setLayout(null);
jid = new JTextField();
jname= new JTextField();
jsalary= new JTextField();
jid.setBounds(100, 100, 100, 30);
jname.setBounds(100, 150, 100, 30);
jsalary.setBounds(100, 200, 100, 30);
add(jid);

add(jname);
add(jsalary);
for (int i = 0; i < e.length; i++) {

if(e[i].getEmpId()==id)
{
jid.setText(Integer.toString(e[i].getEmpId()));
jname.setText(e[i].getEmpName());
jsalary.setText(Double.toString(e[i].getEmpSalary()));
}
}

Class addPanel

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.employee.Employee;

@SuppressWarnings("serial")
public class AddPanel extends JPanel
{

private JLabel jLabel,jLabel2,jLabel3;


private JTextField jTextField,jTextField2,jTextField3;

public AddPanel()
{
setLayout(null);
jLabel= new JLabel("Enter Id");
jLabel.setBounds(20, 50, 100, 30);
add(jLabel);
jLabel2= new JLabel("Enter Name");
jLabel2.setBounds(20, 100, 100, 30);
add(jLabel2);

jLabel3= new JLabel("Enter Salary");


jLabel3.setBounds(20, 150, 100, 30);
add(jLabel3);
jTextField= new JTextField();
jTextField.setBounds(100, 50, 100, 30);
add(jTextField);
jTextField2= new JTextField();
jTextField2.setBounds(100, 100, 100, 30);
add(jTextField2);
jTextField3= new JTextField();
jTextField3.setBounds(100, 150, 100, 30);
add(jTextField3);

}
public Employee[] display(Employee e[] )
{
Employee employee[]= new Employee[e.length+1];
int i=0;
for (i = 0; i < e.length; i++)
{
employee[i]=e[i];

employee[i]=new
Employee(Integer.parseInt(jTextField.getText()),jTextField2.getText(),Double.parseDouble(jTextField3.ge
tText()));
return employee;
}

Class Main:import java.awt.Color;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import com.employee.Employee;
import com.searchpanel.AddPanel;
import com.searchpanel.SearchPanel;

@SuppressWarnings("serial")

public class Test extends JFrame


{
Employee []e= new Employee[2];

private JButton jsearch,jadd,jdelete,jexit,jok;


private JLabel jLabel;
private JTextField jTextField;
private JPanel jPanel,jPanel2;
private JTable jTable;

public Test()
{

e[0]=new Employee(1,"shekhar",500.5);
e[1]= new Employee(2, "saste", 500000.50);
setLayout(null);
jadd= new JButton("ADD");
jdelete= new JButton("DELETE");
jexit= new JButton("Show All");
jsearch= new JButton("SEARCH");
jsearch.setBounds(100, 150, 100, 30);
jadd.setBounds(100, 200, 100, 30);
jdelete.setBounds(100, 250, 100, 30);
jexit.setBounds(100, 300, 100, 30);

add(jsearch);
add(jadd);
add(jdelete);
add(jexit);
jok= new JButton("OK");
jok.setBounds(400, 150, 100, 30);
add(jok);
jok.setVisible(false);
jLabel= new JLabel("Enter Id=");
jLabel.setBounds(200, 150, 100, 30);
add(jLabel);
jLabel.setVisible(false);
jTextField= new JTextField();
jTextField.setBounds(300, 150, 100, 30);
add(jTextField);
jTextField.setVisible(false);

jsearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
jLabel.setVisible(true);
jTextField.setVisible(true);

jok.setVisible(true);
}
});
jok.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0)


{
int id=0;
id=Integer.parseInt(jTextField.getText());
//jPanel= new JPanel();
jPanel= new SearchPanel(e,id);
jPanel.setBounds(200, 200, 300, 300);
add(jPanel);
jPanel.setBackground(Color.PINK);
}
});
jadd.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
/*

jLabel.setVisible(false);
jTextField.setVisible(false);
jok.setVisible(false);
jPanel.setVisible(true);*/

jPanel2= new AddPanel();


jPanel2.setBounds(250, 0, 200, 200);
add(jPanel2);

/*AddPanel addPanel= new AddPanel();


e=addPanel.display(e);*/

jPanel2.setBackground(Color.CYAN);

}
});
jexit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0)


{
int i=0;
Object
[][]info={{e[i].getEmpId(),e[i].getEmpName(),e[i].getEmpSalary()}};

Object []name={"EMPloyee ID","EMPloyee NAme","Employee SAlary"};

jTable= new JTable(info, name);

JScrollPane jScrollPane= new JScrollPane(jTable);

jScrollPane.setBounds(350, 30, 300, 300);


add(jScrollPane);
jScrollPane.setBackground(Color.YELLOW);

}
});

}
public static void main(String[] args)
{

JFrame frame= new Test();


frame.setVisible(true);
frame.setSize(1000, 500);
frame.setLocation(150, 150);
//frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

You might also like