-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkerProcess.java
499 lines (409 loc) · 16.6 KB
/
WorkerProcess.java
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
//package Classes;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.border.Border;
import static javax.swing.JOptionPane.showMessageDialog;
import javax.swing.table.DefaultTableModel;
public class WorkerProcess extends JFrame implements ActionListener, MouseListener {
Container c;
JLabel WorkerProcess, WorkerInfo, WorkerName, WorkerPass, SearchWorker, removeWorker, WorkerID, PhoneNumber, x;
JTextField WorkerNameTF, WorkerPassTF, WorkerIDTF, SearchWorkerTF, PhoneNumberTF, RemoveTF;
JButton JBtnInsert, JBtnExit, JBtnClear, JBtnBack, JBtnSearch, JBtnRemove, JBtnShowAll;
ImageIcon backG, icon;
JLabel imgLabel;
ListIterator li = null;
ArrayList<Worker> al = new ArrayList<>();
DefaultTableModel dtm;
String header[] = new String[]{"Worker Name", "Worker ID", "Worker Password", "Phone Number"};
int row;
Worker data;
JTable jt;
@SuppressWarnings("deprecation")
public WorkerProcess() {
this.setSize(1400, 700);
this.setResizable(false);
this.setTitle("Rent Management");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
Border border = BorderFactory.createLineBorder(Color.black, 2);
c = new Container();
c.setLayout(null);
c.resize(1400, 700);
c.setBackground(Color.decode("#d9ebf6"));
this.add(c);
// Icon
icon = new ImageIcon(getClass().getResource("/images/icon.png"));
this.setIconImage(icon.getImage());
//Table
jt = new JTable();
jt.setName("Worker List");
jt.setBorder(border);
jt.setBounds(700, 150, 600, 250);
//jt.setSize(600, 400);
JScrollPane jps = new JScrollPane();
add(jps);
jt.setPreferredScrollableViewportSize(new Dimension(600, 400));
jt.setFillsViewportHeight(true);
jt.setFont(new Font("Segoe UI", 1, 16));
//JScrollPane jScrollPane = new JScrollPane(jps);
this.getContentPane().add(jps);
al = new ArrayList<>();
dtm = new DefaultTableModel(header, 0);
jt.setModel(dtm);
c.add(jt);
// WorkerProcess Label
WorkerProcess = new JLabel();
WorkerProcess.setText("WORKER'S PROCESS");
WorkerProcess.setBounds(570, 25, 450, 50);
WorkerProcess.setFont(new Font("Segoe UI Black", 1, 36));
WorkerProcess.setForeground(new Color(102, 102, 102));
c.add(WorkerProcess);
//WorkerInfo Label
WorkerInfo = new JLabel();
WorkerInfo.setText("Input Worker's Informations: ");
WorkerInfo.setBounds(30, 100, 650, 60);
WorkerInfo.setFont(new Font("Segoe UI Black", 1, 35));
WorkerInfo.setForeground(new Color(102, 102, 102));
c.add(WorkerInfo);
//WorkerName Label
WorkerName = new JLabel();
WorkerName.setText("Name: ");
WorkerName.setBounds(30, 200, 500, 60);
WorkerName.setFont(new Font("Segoe UI Black", 1, 25));
WorkerName.setForeground(new Color(102, 102, 102));
c.add(WorkerName);
//WorkerID Label
WorkerID = new JLabel();
WorkerID.setText("ID: ");
WorkerID.setBounds(30, 300, 500, 60);
WorkerID.setFont(new Font("Segoe UI Black", 1, 25));
WorkerID.setForeground(new Color(102, 102, 102));
c.add(WorkerID);
//WorkerPass Label
WorkerPass = new JLabel();
WorkerPass.setText("Password: ");
WorkerPass.setBounds(30, 250, 500, 60);
WorkerPass.setFont(new Font("Segoe UI Black", 1, 25));
WorkerPass.setForeground(new Color(102, 102, 102));
c.add(WorkerPass);
//PhoneNumber Label
PhoneNumber = new JLabel();
PhoneNumber.setText("Phone Number: ");
PhoneNumber.setBounds(30, 325, 500, 100);
PhoneNumber.setFont(new Font("Segoe UI Black", 1, 25));
PhoneNumber.setForeground(new Color(102, 102, 102));
c.add(PhoneNumber);
//x Label
x = new JLabel();
x.setText("Name: ID: Password: Phone No:");
x.setBounds(700, 100, 900, 60);
x.setFont(new Font("Segoe UI Black", 1, 20));
x.setForeground(new Color(102, 102, 102));
c.add(x);
//WorkerNameTF TextField
WorkerNameTF = new JTextField();
WorkerNameTF.setBounds(250, 210, 300, 40);
WorkerNameTF.setFont(new Font("Segoe UI Black", 1, 20));
WorkerNameTF.setBorder(border);
c.add(WorkerNameTF);
//WorkerPassTF TextField
WorkerPassTF = new JTextField();
WorkerPassTF.setBounds(250, 260, 300, 40);
WorkerPassTF.setFont(new Font("Segoe UI Black", 1, 20));
WorkerPassTF.setBorder(border);
c.add(WorkerPassTF);
//WorkerIDTF TextField
WorkerIDTF = new JTextField();
WorkerIDTF.setBounds(250, 310, 300, 40);
WorkerIDTF.setFont(new Font("Segoe UI Black", 1, 20));
WorkerIDTF.setBorder(border);
c.add(WorkerIDTF);
//PhoneNumberTF TextField
PhoneNumberTF = new JTextField();
PhoneNumberTF.setBounds(250, 360, 300, 40);
PhoneNumberTF.setFont(new Font("Segoe UI Black", 1, 20));
PhoneNumberTF.setBorder(border);
c.add(PhoneNumberTF);
//removeWorker Label
removeWorker = new JLabel();
removeWorker.setText("Remove Worker: ");
removeWorker.setBounds(700, 405, 400, 50);
removeWorker.setFont(new Font("Segoe UI Black", 1, 30));
removeWorker.setForeground(new Color(102, 102, 102));
c.add(removeWorker);
//SearchWorker Label
SearchWorker = new JLabel();
SearchWorker.setText("Search Worker: ");
SearchWorker.setBounds(700, 505, 400, 50);
SearchWorker.setFont(new Font("Segoe UI Black", 1, 30));
SearchWorker.setForeground(new Color(102, 102, 102));
c.add(SearchWorker);
//Worker Remove ID Label
WorkerID = new JLabel();
WorkerID.setText("ID: ");
WorkerID.setBounds(700, 435, 500, 60);
WorkerID.setFont(new Font("Segoe UI Black", 1, 25));
WorkerID.setForeground(new Color(102, 102, 102));
c.add(WorkerID);
//Worker Search ID Label
WorkerID = new JLabel();
WorkerID.setText("ID: ");
WorkerID.setBounds(700, 535, 500, 60);
WorkerID.setFont(new Font("Segoe UI Black", 1, 25));
WorkerID.setForeground(new Color(102, 102, 102));
c.add(WorkerID);
//remove Worker TextField
RemoveTF = new JTextField();
RemoveTF.setBounds(750, 450, 150, 40);
RemoveTF.setFont(new Font("Segoe UI Black", 1, 20));
RemoveTF.setBorder(border);
c.add(RemoveTF);
//SearchWorker TextField
SearchWorkerTF = new JTextField();
SearchWorkerTF.setBounds(750, 550, 150, 40);
SearchWorkerTF.setFont(new Font("Segoe UI Black", 1, 20));
SearchWorkerTF.setBorder(border);
c.add(SearchWorkerTF);
// Search Button
JBtnSearch = new JButton();
JBtnSearch.addActionListener(this);
JBtnSearch.addMouseListener(this);
JBtnSearch.setText("Search");
JBtnSearch.setFont(new Font("Segoe UI Black", 1, 30));
JBtnSearch.setForeground(new Color(255, 255, 255));
JBtnSearch.setBackground(new Color(0, 107, 60));
JBtnSearch.setFocusable(false);
JBtnSearch.setBounds(925, 550, 160, 55);
c.add(JBtnSearch);
//JBtnSearch.setBorder(border);
// Remove Button
JBtnRemove = new JButton();
JBtnRemove.addActionListener(this);
JBtnRemove.addMouseListener(this);
JBtnRemove.setText("Remove");
JBtnRemove.setFont(new Font("Segoe UI Black", 1, 30));
JBtnRemove.setForeground(new Color(255, 255, 255));
JBtnRemove.setBackground(new Color(0, 107, 60));
JBtnRemove.setFocusable(false);
JBtnRemove.setBounds(925, 450, 160, 55);
c.add(JBtnRemove);
//JBtnRemove.setBorder(border);
// ShowAll Button
JBtnShowAll = new JButton();
JBtnShowAll.addActionListener(this);
JBtnShowAll.addMouseListener(this);
JBtnShowAll.setText("Show All");
JBtnShowAll.setFont(new Font("Segoe UI Black", 1, 20));
JBtnShowAll.setForeground(new Color(255, 255, 255));
JBtnShowAll.setBackground(new Color(154,206, 235));
JBtnShowAll.setFocusable(false);
JBtnShowAll.setBounds(1150, 460, 150, 150);
c.add(JBtnShowAll);
JBtnShowAll.setBorder(border);
// Exit Button
JBtnExit = new JButton();
JBtnExit.addActionListener(this);
JBtnExit.addMouseListener(this);
JBtnExit.setText("Exit");
JBtnExit.setFont(new Font("Segoe UI Black", 1, 30));
JBtnExit.setForeground(new Color(255, 255, 255));
JBtnExit.setBackground(new Color(160, 16, 16));
JBtnExit.setFocusable(false);
JBtnExit.setBounds(70, 570, 200, 60);
c.add(JBtnExit);
// Back Button
JBtnBack = new JButton();
JBtnBack.addActionListener(this);
JBtnBack.addMouseListener(this);
JBtnBack.setText("Back");
JBtnBack.setFont(new Font("Segoe UI Black", 1, 30));
JBtnBack.setForeground(new Color(255, 255, 255));
JBtnBack.setBackground(new Color(0,128, 0));
JBtnBack.setFocusable(false);
JBtnBack.setBounds(320, 570, 200, 60);
c.add(JBtnBack);
// Insert Button
JBtnInsert = new JButton();
JBtnInsert.addActionListener(this);
JBtnInsert.addMouseListener(this);
JBtnInsert.setText("Insert");
JBtnInsert.setFont(new Font("Segoe UI Black", 1, 30));
JBtnInsert.setForeground(new Color(255, 255, 255));
JBtnInsert.setBackground(new Color(0, 107, 60));
JBtnInsert.setFocusable(false);
JBtnInsert.setBounds(250, 415, 150, 50);
c.add(JBtnInsert);
//Clear Button
JBtnClear = new JButton();
JBtnClear.addActionListener(this);
JBtnClear.addMouseListener(this);
JBtnClear.setText("Clear");
JBtnClear.setFont(new Font("Segoe UI Black", 1, 30));
JBtnClear.setForeground(new Color(255, 255, 255));
JBtnClear.setBackground(new Color(0, 107, 60));
JBtnClear.setFocusable(false);
JBtnClear.setBounds(430, 415, 150, 50);
c.add(JBtnClear);
}
public void ShowAllWorker() {
dtm.setRowCount(0);
for (int i = 0; i < al.size(); i++) {
Object[] obj = {al.get(i).wName, al.get(i).wID, al.get(i).workerPwd, al.get(i).phonenNo};
dtm.addRow(obj);
}
}
public void ShowList() {
li = al.listIterator();
while (li.hasNext()) {
//showMessageDialog(null, li.next());
System.out.println("***********************************\n");
System.out.println(li.next());
System.out.println("");
}
}
public void removeWorker() {
boolean found = false;
String id = RemoveTF.getText();
li = al.listIterator();
while (li.hasNext()) {
Worker w = (Worker) li.next();
if (w.wID.equals(id)) {
try {
int choice = JOptionPane.showConfirmDialog(null, "Delete this data ?", "Delete", JOptionPane.YES_NO_OPTION);
if (choice == 0) {
li.remove();
dtm.removeRow(row);
//al.remove(row);
ShowAllWorker();
}
found = true;
showMessageDialog(null, "Worker Removed Successfully");
if (!found) {
showMessageDialog(null, "Worker Not found!");
}
} catch (ArrayIndexOutOfBoundsException e) {
showMessageDialog(null, "ArrayIndexOutOfBoundsException Handled ");
}
}
}
}
public void searchWorker() {
boolean found = false;
String id = SearchWorkerTF.getText();
li = al.listIterator();
while (li.hasNext()) {
Worker w = (Worker) li.next();
if (w.wID.equals(id)) {
showMessageDialog(null, w + " Worker Found");
System.out.println(w);
found = true;
}
}
if (!found) {
showMessageDialog(null, "Worker Not found!");
}
//System.out.println("Not Found!");
}
//Mouse performed by Mouse listner
@Override
public void mouseClicked(MouseEvent me) {
}
@Override
public void mousePressed(MouseEvent me) {
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseEntered(MouseEvent me) {
}
@Override
public void mouseExited(MouseEvent me) {
}
//Action Performed by Listener
@Override
public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand();
String name = WorkerNameTF.getText();
String id = WorkerIDTF.getText();
String pwd = WorkerPassTF.getText();
String phn = PhoneNumberTF.getText();
if (JBtnRemove.getText().equals(command)) {
removeWorker();
}
if (JBtnShowAll.getText().equals(command)) {
ShowAllWorker sa = new ShowAllWorker();
this.setVisible(true);
sa.setVisible(true);
ShowList();
}
if (ae.getSource() == JBtnSearch) {
searchWorker();
FileWriter fw = null;
try {
String filePath = "WorkerList.txt";
File file1 = new File(filePath);
fw = new FileWriter(file1);
BufferedWriter bw = new BufferedWriter(fw);
for (int i = 0; i < jt.getRowCount(); i++) {//rows
for (int j = 0; j < jt.getColumnCount(); j++) {//columns
bw.write(jt.getValueAt(i, j).toString() + " ");
}
bw.newLine();
}
bw.close();
fw.close();
} catch (IOException ex) {
}
//ShowList();
}
if (JBtnInsert.getText().equals(command)) {
FileWriter fw = null;
try {
String filePath = "WorkerFile.txt";
File file = new File(filePath);
fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
Worker Data = new Worker(name, id, pwd, phn);
al.add(Data);
//String data = Data.toString();
String data = "Name : " + WorkerNameTF.getText() + "\n" +WorkerIDTF.getText() + "\n" +WorkerPassTF.getText();
bw.write(data);
bw.close();
fw.close();
ShowAllWorker();
showMessageDialog(null, " Congraturalation ! \n Worker has been Inserted ", "Rent Management", JOptionPane.PLAIN_MESSAGE);
} catch (IOException ex) {
}
finally{
}
}
if (JBtnClear.getText().equals(command)) {
WorkerNameTF.setText(null);
WorkerIDTF.setText(null);
WorkerPassTF.setText(null);
PhoneNumberTF.setText(null);
}
if (JBtnBack.getText().equals(command)) {
WorkerOptions frame = new WorkerOptions();
frame.setVisible(true);
this.setVisible(false);
}
if (JBtnExit.getText().equals(command)) {
System.exit(0);
}
}
public static void main(String[] args){
WorkerProcess frame= new WorkerProcess();
frame.setVisible(true);
}
}