-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView_Employee.java
More file actions
106 lines (89 loc) · 3.1 KB
/
View_Employee.java
File metadata and controls
106 lines (89 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package employee.management.stystem;
import net.proteanit.sql.DbUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
public class View_Employee extends JFrame implements ActionListener {
JTable table;
Choice choiceEMP;
JButton searchbtn, print, update, back;
View_Employee(){
getContentPane().setBackground(new Color(255,131,122));
JLabel search = new JLabel("Search by employee id");
search.setBounds(20,20,150,20);
add(search);
choiceEMP = new Choice();
choiceEMP.setBounds(180,20,150,20);
add(choiceEMP);
try{
conn c = new conn();
ResultSet resultSet = c.statement.executeQuery("select * from employee");
while (resultSet.next()){
choiceEMP.add(resultSet.getString("empId"));
}
}catch (Exception e){
e.printStackTrace();
}
table = new JTable();
try{
conn c= new conn();
ResultSet resultSet = c.statement.executeQuery("select * from employee");
table.setModel(DbUtils.resultSetToTableModel(resultSet));
}catch (Exception e){
e.printStackTrace();
}
JScrollPane jp = new JScrollPane(table);
jp.setBounds(0,100,900,600);
add(jp);
searchbtn = new JButton("Search");
searchbtn.setBounds(20,70,80,20);
searchbtn.addActionListener(this);
add(searchbtn);
print = new JButton("Print");
print.setBounds(120,70,80,20);
print.addActionListener(this);
add(print);
update = new JButton("Update");
update.setBounds(220,70,80,20);
update.addActionListener(this);
add(update);
back = new JButton("Back");
back.setBounds(320,70,80,20);
back.addActionListener(this);
add(back);
setSize(900,700);
setLayout(null);
setLocation(300,100);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == searchbtn){
String query = "select * from employee where empId = '"+choiceEMP.getSelectedItem()+"'";
try {
conn c = new conn();
ResultSet resultSet = c.statement.executeQuery(query);
table.setModel(DbUtils.resultSetToTableModel(resultSet));
}catch (Exception E){
E.printStackTrace();
}
} else if (e.getSource() == print) {
try {
table.print();
}catch (Exception E){
E.printStackTrace();
}
} else if (e.getSource() == update){
setVisible(false);
new UpdateEmployee(choiceEMP.getSelectedItem());
} else {
setVisible(false);
new Main_class();
}
}
public static void main(String[] args) {
new View_Employee();
}
}