Repository navigation
Expand file tree
/
Copy pathAddEmployee.java
More file actions
205 lines (172 loc) · 7.65 KB
/
Copy pathAddEmployee.java
File metadata and controls
205 lines (172 loc) · 7.65 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package Hotel.Management.System;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Statement;
public class AddEmployee extends JFrame implements ActionListener {
JTextField nameText, ageText, salaryText, phoneText, aadharText, emailText;
JRadioButton radioButtonM, radioButtonF;
JComboBox<String> comboBox;
JButton add, back;
AddEmployee() {
JPanel panel = new JPanel();
panel.setBounds(5, 5, 890, 490);
panel.setLayout(null);
panel.setBackground(new Color(3, 45, 48));
add(panel);
JLabel name = new JLabel("NAME");
name.setBounds(60, 30, 150, 27);
name.setFont(new Font("serif", Font.BOLD, 17));
name.setForeground(Color.WHITE);
panel.add(name);
nameText = new JTextField();
nameText.setBounds(200, 30, 150, 27);
nameText.setBackground(new Color(16, 108, 115));
nameText.setFont(new Font("Tahoma", Font.BOLD, 14));
nameText.setForeground(Color.WHITE);
panel.add(nameText);
JLabel Age = new JLabel("AGE");
Age.setBounds(60, 80, 150, 27);
Age.setFont(new Font("serif", Font.BOLD, 17));
Age.setForeground(Color.WHITE);
panel.add(Age);
ageText = new JTextField();
ageText.setBounds(200, 80, 150, 27);
ageText.setBackground(new Color(16, 108, 115));
ageText.setFont(new Font("Tahoma", Font.BOLD, 14));
ageText.setForeground(Color.WHITE);
panel.add(ageText);
JLabel gender = new JLabel("GENDER");
gender.setBounds(60, 120, 150, 27);
gender.setFont(new Font("serif", Font.BOLD, 17));
gender.setForeground(Color.WHITE);
panel.add(gender);
radioButtonM = new JRadioButton("MALE");
radioButtonM.setBounds(200, 120, 70, 27);
radioButtonM.setBackground(new Color(3, 45, 48));
radioButtonM.setFont(new Font("Tahoma", Font.BOLD, 14));
radioButtonM.setForeground(Color.WHITE);
panel.add(radioButtonM);
radioButtonF = new JRadioButton("FEMALE");
radioButtonF.setBounds(280, 120, 100, 27);
radioButtonF.setBackground(new Color(3, 45, 48));
radioButtonF.setFont(new Font("Tahoma", Font.BOLD, 14));
radioButtonF.setForeground(Color.WHITE);
panel.add(radioButtonF);
ButtonGroup bg = new ButtonGroup();
bg.add(radioButtonM);
bg.add(radioButtonF);
JLabel job = new JLabel("JOB");
job.setBounds(60, 170, 150, 27);
job.setFont(new Font("serif", Font.BOLD, 17));
job.setForeground(Color.WHITE);
panel.add(job);
comboBox = new JComboBox<>(new String[]{"Front Desk", "Housekeeping", "Kitchen Staff", "Room Service", "Manager", "Accountant", "Chef"});
comboBox.setBackground(new Color(16, 108, 115));
comboBox.setBounds(200, 170, 150, 30);
comboBox.setFont(new Font("Tahoma", Font.BOLD, 14));
comboBox.setForeground(Color.WHITE);
panel.add(comboBox);
JLabel salary = new JLabel("SALARY");
salary.setBounds(60, 220, 150, 27);
salary.setFont(new Font("serif", Font.BOLD, 17));
salary.setForeground(Color.WHITE);
panel.add(salary);
salaryText = new JTextField();
salaryText.setBounds(200, 220, 150, 27);
salaryText.setBackground(new Color(16, 108, 115));
salaryText.setFont(new Font("Tahoma", Font.BOLD, 14));
salaryText.setForeground(Color.WHITE);
panel.add(salaryText);
JLabel phone = new JLabel("PHONE");
phone.setBounds(60, 270, 150, 27);
phone.setFont(new Font("serif", Font.BOLD, 17));
phone.setForeground(Color.WHITE);
panel.add(phone);
phoneText = new JTextField();
phoneText.setBounds(200, 270, 150, 27);
phoneText.setBackground(new Color(16, 108, 115));
phoneText.setFont(new Font("Tahoma", Font.BOLD, 14));
phoneText.setForeground(Color.WHITE);
panel.add(phoneText);
JLabel aadhar = new JLabel("AADHAR");
aadhar.setBounds(60, 320, 150, 27);
aadhar.setFont(new Font("serif", Font.BOLD, 17));
aadhar.setForeground(Color.WHITE);
panel.add(aadhar);
aadharText = new JTextField();
aadharText.setBounds(200, 320, 150, 27);
aadharText.setBackground(new Color(16, 108, 115));
aadharText.setFont(new Font("Tahoma", Font.BOLD, 14));
aadharText.setForeground(Color.WHITE);
panel.add(aadharText);
JLabel email = new JLabel("EMAIL");
email.setBounds(60, 370, 150, 27);
email.setFont(new Font("serif", Font.BOLD, 17));
email.setForeground(Color.WHITE);
panel.add(email);
emailText = new JTextField();
emailText.setBounds(200, 370, 150, 27);
emailText.setBackground(new Color(16, 108, 115));
emailText.setFont(new Font("Tahoma", Font.BOLD, 14));
emailText.setForeground(Color.WHITE);
panel.add(emailText);
JLabel AED = new JLabel("ADD EMPLOYEE DETAILS");
AED.setBounds(450, 24, 445, 35);
AED.setFont(new Font("Tahoma", Font.BOLD, 31));
AED.setForeground(Color.WHITE);
panel.add(AED);
add = new JButton("ADD");
add.setBounds(80, 420, 100, 30);
add.setBackground(Color.BLACK);
add.setForeground(Color.WHITE);
add.addActionListener(this);
panel.add(add);
back = new JButton("BACK");
back.setBounds(200, 420, 100, 30);
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
back.addActionListener(this);
panel.add(back);
setUndecorated(true);
setLocation(60, 160);
setLayout(null);
setSize(900, 500);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == add) {
String name = nameText.getText().trim();
String age = ageText.getText().trim();
String salary = salaryText.getText().trim();
String phone = phoneText.getText().trim();
String email = emailText.getText().trim();
String aadhar = aadharText.getText().trim();
String job = (String) comboBox.getSelectedItem();
String gender = null;
if (radioButtonM.isSelected()) gender = "Male";
else if (radioButtonF.isSelected()) gender = "Female";
if (name.isEmpty() || age.isEmpty() || salary.isEmpty() || phone.isEmpty() ||
email.isEmpty() || aadhar.isEmpty() || gender == null) {
JOptionPane.showMessageDialog(null, "Please fill all fields before adding an employee.");
return;
}
try {
connection c = new connection();
String q = "INSERT INTO employee VALUES('" + name + "', '" + age + "', '" + gender + "', '" + job + "', '" + salary + "','" + phone + "', '" + email + "', '" + aadhar + "')";
c.statement.executeUpdate(q);
JOptionPane.showMessageDialog(null, "Employee Added Successfully");
setVisible(false);
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Error adding employee: " + ex.getMessage());
}
} else {
setVisible(false);
}
}
public static void main(String[] args) {
new AddEmployee();
}
}