-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddEmployeeDialog.java
More file actions
731 lines (612 loc) · 34.9 KB
/
AddEmployeeDialog.java
File metadata and controls
731 lines (612 loc) · 34.9 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
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.awt.Color;
/**
*
* @author 565174
*/
public class AddEmployeeDialog extends javax.swing.JDialog {
//ATTRIBUTES
private Color red;
private Color black;
/**
* Creates new form AddEmployeeDialog
*/
public AddEmployeeDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
//Set Colors
black = new Color(0,0,0);
red = new Color(255,0,0);
//Set partTimeRadioButton as selected so that there is never a scenario where both buttons are not selected.
//Automatically calls partTimeRadioButtonStateChanged and updates PTEmp options
partTimeRadioButton.setSelected(true);
//Set work location combo box model
workLocationComboBox.setModel(MainJFrame.workLocationModel);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
partOrFullTimeButtonGroup = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
hourlyWageLabel = new javax.swing.JLabel();
hoursPerWeekLabel = new javax.swing.JLabel();
weeksPerYearLabel = new javax.swing.JLabel();
annualSalaryLabel = new javax.swing.JLabel();
employeeNumberTextField = new javax.swing.JTextField();
firstNameTextField = new javax.swing.JTextField();
lastNameTextField = new javax.swing.JTextField();
hoursPerWeekTextField = new javax.swing.JTextField();
hourlyWageTextField = new javax.swing.JTextField();
weeksPerYearTextField = new javax.swing.JTextField();
annualSalaryTextField = new javax.swing.JTextField();
partTimeRadioButton = new javax.swing.JRadioButton();
fullTimeRadioButton = new javax.swing.JRadioButton();
addEmployeeButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
deductionRateTextField = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
genderComboBox = new javax.swing.JComboBox<>();
workLocationComboBox = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Add Employee Wizard", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), new java.awt.Color(255, 153, 153))); // NOI18N
jLabel1.setText("To add an Employee, fill out all required fields and click \"Add\".");
jLabel2.setText("Employee Number:");
jLabel3.setText("First Name:");
jLabel4.setText("Last Name:");
jLabel5.setText("Part or Full Time Status:");
hourlyWageLabel.setText("Hourly Wage:");
hoursPerWeekLabel.setText("Hours Per Week:");
weeksPerYearLabel.setText("Weeks Per Year:");
annualSalaryLabel.setText("Annual Salary:");
employeeNumberTextField.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
employeeNumberTextFieldMouseClicked(evt);
}
});
hoursPerWeekTextField.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
hoursPerWeekTextFieldMouseClicked(evt);
}
});
hoursPerWeekTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hoursPerWeekTextFieldActionPerformed(evt);
}
});
hourlyWageTextField.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
hourlyWageTextFieldMouseClicked(evt);
}
});
weeksPerYearTextField.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
weeksPerYearTextFieldMouseClicked(evt);
}
});
annualSalaryTextField.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
annualSalaryTextFieldMouseClicked(evt);
}
});
partOrFullTimeButtonGroup.add(partTimeRadioButton);
partTimeRadioButton.setText("Part-Time");
partTimeRadioButton.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
partTimeRadioButtonStateChanged(evt);
}
});
partOrFullTimeButtonGroup.add(fullTimeRadioButton);
fullTimeRadioButton.setText("Full-Time");
addEmployeeButton.setText("Add");
addEmployeeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addEmployeeButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
jLabel6.setText("Deduction Rate:");
deductionRateTextField.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
deductionRateTextFieldMouseClicked(evt);
}
});
jLabel7.setText("Gender:");
jLabel8.setText("Work Location:");
genderComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Male", "Female", "Other" }));
workLocationComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(addEmployeeButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cancelButton))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(66, 66, 66)
.addComponent(partTimeRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 312, Short.MAX_VALUE)
.addComponent(fullTimeRadioButton)
.addGap(81, 81, 81))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lastNameTextField)
.addComponent(firstNameTextField)
.addComponent(deductionRateTextField)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(employeeNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(workLocationComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(genderComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, 111, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(7, 7, 7)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(hoursPerWeekLabel)
.addComponent(hourlyWageLabel)
.addComponent(weeksPerYearLabel)
.addComponent(annualSalaryLabel))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(annualSalaryTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(hourlyWageTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
.addComponent(hoursPerWeekTextField, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(weeksPerYearTextField)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 345, Short.MAX_VALUE)))
.addContainerGap(20, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(employeeNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(firstNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(lastNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(deductionRateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(genderComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(workLocationComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(partTimeRadioButton)
.addComponent(fullTimeRadioButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hourlyWageLabel)
.addComponent(hourlyWageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hoursPerWeekLabel)
.addComponent(hoursPerWeekTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(weeksPerYearLabel)
.addComponent(weeksPerYearTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(annualSalaryLabel)
.addComponent(annualSalaryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(54, 54, 54)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addEmployeeButton)
.addComponent(cancelButton))
.addGap(15, 15, 15))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
//OTHER METHODS
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO add your handling code here:
//Closes Add Employee Dialog Box
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void partTimeRadioButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_partTimeRadioButtonStateChanged
// TODO add your handling code here:
//Update Options when partTimeRadioButton state changes
partOrFullTimeOptionsVisibilityUpdate();
}//GEN-LAST:event_partTimeRadioButtonStateChanged
private void addEmployeeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addEmployeeButtonActionPerformed
// TODO add your handling code here:
//Get Employee
EmployeeInfo addedEmployee = createEmployeeFromFields();
//Catch if addedEmployee was not created properly (addedEmployee.employeeNumber = -1)
//If caught, add to table and updatetablevalues methods are not performed!
if (addedEmployee.employeeNumber == -1){
return;
}
//Add employee to hash table
MainJFrame.employeeHashTable.addToTable(addedEmployee);
//Update main table values in MainJFrame
MainJFrame.updateTableValuesFromHashTable();
//Dispose of Dialog Box
dispose();
}//GEN-LAST:event_addEmployeeButtonActionPerformed
private void employeeNumberTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_employeeNumberTextFieldMouseClicked
// TODO add your handling code here:
//Sets text to an empty string and changes text color IF RED (as in the result of NumberFormatException)
if (employeeNumberTextField.getForeground() == red){
employeeNumberTextField.setText("");
employeeNumberTextField.setForeground(black);
}
}//GEN-LAST:event_employeeNumberTextFieldMouseClicked
private void deductionRateTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_deductionRateTextFieldMouseClicked
// TODO add your handling code here:
//Sets text to an empty string and changes text color IF RED (as in the result of NumberFormatException)
if (deductionRateTextField.getForeground() == red){
deductionRateTextField.setText("");
deductionRateTextField.setForeground(black);
}
}//GEN-LAST:event_deductionRateTextFieldMouseClicked
private void hourlyWageTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hourlyWageTextFieldMouseClicked
// TODO add your handling code here:
//Sets text to an empty string and changes text color IF RED (as in the result of NumberFormatException)
if (hourlyWageTextField.getForeground() == red){
hourlyWageTextField.setText("");
hourlyWageTextField.setForeground(black);
}
}//GEN-LAST:event_hourlyWageTextFieldMouseClicked
private void hoursPerWeekTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_hoursPerWeekTextFieldMouseClicked
// TODO add your handling code here:
//Sets text to an empty string and changes text color IF RED (as in the result of NumberFormatException)
if (hoursPerWeekTextField.getForeground() == red){
hoursPerWeekTextField.setText("");
hoursPerWeekTextField.setForeground(black);
}
}//GEN-LAST:event_hoursPerWeekTextFieldMouseClicked
private void weeksPerYearTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_weeksPerYearTextFieldMouseClicked
// TODO add your handling code here:
//Sets text to an empty string and changes text color IF RED (as in the result of NumberFormatException)
if (weeksPerYearTextField.getForeground() == red){
weeksPerYearTextField.setText("");
weeksPerYearTextField.setForeground(black);
}
}//GEN-LAST:event_weeksPerYearTextFieldMouseClicked
private void annualSalaryTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_annualSalaryTextFieldMouseClicked
// TODO add your handling code here:
//Sets text to an empty string and changes text color IF RED (as in the result of NumberFormatException)
if (annualSalaryTextField.getForeground() == red){
annualSalaryTextField.setText("");
annualSalaryTextField.setForeground(black);
}
}//GEN-LAST:event_annualSalaryTextFieldMouseClicked
private void hoursPerWeekTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hoursPerWeekTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_hoursPerWeekTextFieldActionPerformed
private EmployeeInfo createEmployeeFromFields(){
//If Employee is not created properly and the exception is caught, the catch block will set the employeeNumber to -1.
//exceptions array is used to keep track of exceptions occurring for each category, 0 means exception has not occurred, 1 means it has.
int[] exceptions = new int[6];
for(int x = 0; x < 6; x++){
exceptions[x] = 0;
}
//Declare Employee
EmployeeInfo employee = null;
//Get Employee Number; Catches NumberFormatException
//Instantiate Emp Num outside of try block
int employeeNumber = -1;
try{
employeeNumber = Integer.parseInt(employeeNumberTextField.getText());
}catch(java.lang.NumberFormatException ex){
employeeNumberTextField.setForeground(red);
employeeNumberTextField.setText("ERROR: Invalid Integer.");
exceptions[0] = 1;
}
//Catch exception where employee number is negative
if(employeeNumber < 0 && exceptions[0]==0){
employeeNumberTextField.setForeground(red);
employeeNumberTextField.setText("ERROR: Positive Integers Only.");
employeeNumber = -1;
exceptions[0] = 1;
}
//Catch exception where employee number is already in use; skip if employee number is -1 (error)
if(employeeNumber > -1 && exceptions[0]==0){
if(MainJFrame.employeeHashTable.isInTable(employeeNumber) == true){
employeeNumberTextField.setForeground(red);
employeeNumberTextField.setText("ERROR: Employee Number " + employeeNumber + " already in use.");
employeeNumber = -1;
}
}
//Get First Name
String firstName = firstNameTextField.getText();
//Get Last Name
String lastName = lastNameTextField.getText();
//Get Deduction Rate; Catch NumberFormatException
//Instantiate deductionRate outside of try block
double deductionRate = -1;
try{
deductionRate = Double.parseDouble(deductionRateTextField.getText());
}catch(java.lang.NumberFormatException ex){
deductionRateTextField.setForeground(red);
deductionRateTextField.setText("ERROR: Invalid Decimal Number.");
employeeNumber = -1;
exceptions[1] = 1;
}
//Catch if deduction rate is negative
if(deductionRate < 0 && exceptions[1] == 0){
deductionRateTextField.setForeground(red);
deductionRateTextField.setText("ERROR: Positive Decimals Only.");
employeeNumber = -1;
exceptions[1] = 1;
}
//Catch if deduction rate is greater than 1
if(deductionRate > 1 && exceptions[1] == 0){
deductionRateTextField.setForeground(red);
deductionRateTextField.setText("ERROR: Deduction Rate Greater than 1.");
employeeNumber = -1;
}
//Get Gender
String gender = (String)genderComboBox.getSelectedItem();
//Get Work Location
String workLocation = (String)workLocationComboBox.getSelectedItem();
if(checkPartTimeStatus() == true){//For Part Time Employees
//Instantiate hourly wage outside of try block
double hourlyWage = -1;
//Get Hourly Wage
try{
hourlyWage = Double.parseDouble(hourlyWageTextField.getText());
}catch(java.lang.NumberFormatException ex){
hourlyWageTextField.setForeground(red);
hourlyWageTextField.setText("ERROR: Invalid Decimal Number.");
employeeNumber = -1;
exceptions[2] = 1;
}
//Catch if Hourly Wage is negative
if(hourlyWage < 0 && exceptions[2] == 0){
hourlyWageTextField.setForeground(red);
hourlyWageTextField.setText("ERROR: Positive Decimals Only.");
employeeNumber = -1;
}
//Get Hours per week
double hoursPerWeek = -1;
try{
hoursPerWeek = Double.parseDouble(hoursPerWeekTextField.getText());
}catch(java.lang.NumberFormatException ex){
hoursPerWeekTextField.setForeground(red);
hoursPerWeekTextField.setText("ERROR: Invalid Decimal Number.");
employeeNumber = -1;
exceptions[3] = 1;
}
//Catch if Hours per week is negative
if(hoursPerWeek < 0 && exceptions[3]==0){
hoursPerWeekTextField.setForeground(red);
hoursPerWeekTextField.setText("ERROR: Positive Decimals Only.");
employeeNumber = -1;
exceptions[3] = 1;
}
//Catch if Hours per week is greater than 168
if(hoursPerWeek > 168 && exceptions[3]==0){
hoursPerWeekTextField.setForeground(red);
hoursPerWeekTextField.setText("ERROR: HPW Exceeds Natural Max.");
employeeNumber = -1;
}
//Get weeks per year
double weeksPerYear = -1;
try{
weeksPerYear = Double.parseDouble(weeksPerYearTextField.getText());
}catch(java.lang.NumberFormatException ex){
weeksPerYearTextField.setForeground(red);
weeksPerYearTextField.setText("ERROR: Invalid Decimal Number.");
employeeNumber = -1;
exceptions[4] = 1;
}
//Catch if weeks per year is negative
if(weeksPerYear < 0 && exceptions[4] == 0){
weeksPerYearTextField.setForeground(red);
weeksPerYearTextField.setText("ERROR: Positive Decimals Only.");
employeeNumber = -1;
exceptions[4] = 1;
}
//Catch if weeks per year exceeds 52
if(weeksPerYear > 52 && exceptions[4] == 0){
weeksPerYearTextField.setForeground(red);
weeksPerYearTextField.setText("ERROR: WPY Exceeds Natural Max.");
employeeNumber = -1;
}
//Instantiate PTEmp as employee to be returned
employee = new PTEmp(employeeNumber, firstName,lastName, deductionRate, gender, workLocation, hourlyWage, hoursPerWeek, weeksPerYear);
}
else{//For Full Time Employees
//Get Annual Salary
double annualSalary = -1;
try{
annualSalary = Double.parseDouble(annualSalaryTextField.getText());
}catch(java.lang.NumberFormatException ex){
annualSalaryTextField.setForeground(red);
annualSalaryTextField.setText("ERROR: Invalid Decimal Number.");
employeeNumber = -1;
exceptions[5] = 1;
}
//Catch if Annual salary is negative
if(annualSalary < 0 && exceptions[5] == 0){
annualSalaryTextField.setForeground(red);
annualSalaryTextField.setText("ERROR: Positive Decimals Only.");
employeeNumber = -1;
}
//Instantiate FTEmp as employee to be returned
employee = new FTEmp(employeeNumber,firstName,lastName, deductionRate, gender, workLocation, annualSalary);
}
return employee;
}
private void partOrFullTimeOptionsVisibilityUpdate(){
if(checkPartTimeStatus() == true){//If Part Time Employee
//Set all full time options invisible and text fields blank
annualSalaryLabel.setVisible(false);
annualSalaryTextField.setVisible(false);
annualSalaryTextField.setText("");
annualSalaryTextField.setForeground(black);
//Set all part time options visible
hourlyWageLabel.setVisible(true);
hoursPerWeekLabel.setVisible(true);
weeksPerYearLabel.setVisible(true);
hourlyWageTextField.setVisible(true);
hoursPerWeekTextField.setVisible(true);
weeksPerYearTextField.setVisible(true);
}
else{//New Employee is Full Time Employee
//Set all part time options invisible and text fields blank
hourlyWageLabel.setVisible(false);
hoursPerWeekLabel.setVisible(false);
weeksPerYearLabel.setVisible(false);
hourlyWageTextField.setVisible(false);
hoursPerWeekTextField.setVisible(false);
weeksPerYearTextField.setVisible(false);
hourlyWageTextField.setText("");
hoursPerWeekTextField.setText("");
weeksPerYearTextField.setText("");
hourlyWageTextField.setForeground(black);
hoursPerWeekTextField.setForeground(black);
weeksPerYearTextField.setForeground(black);
//Set all full time options true
annualSalaryLabel.setVisible(true);
annualSalaryTextField.setVisible(true);
}
}
private boolean checkPartTimeStatus(){//Returns true for part time, false for full time
return partTimeRadioButton.isSelected();
}
//MAIN METHOD STUFF BELOW
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(AddEmployeeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AddEmployeeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AddEmployeeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AddEmployeeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
AddEmployeeDialog dialog = new AddEmployeeDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addEmployeeButton;
private javax.swing.JLabel annualSalaryLabel;
private javax.swing.JTextField annualSalaryTextField;
private javax.swing.JButton cancelButton;
private javax.swing.JTextField deductionRateTextField;
private javax.swing.JTextField employeeNumberTextField;
private javax.swing.JTextField firstNameTextField;
private javax.swing.JRadioButton fullTimeRadioButton;
private javax.swing.JComboBox<String> genderComboBox;
private javax.swing.JLabel hourlyWageLabel;
private javax.swing.JTextField hourlyWageTextField;
private javax.swing.JLabel hoursPerWeekLabel;
private javax.swing.JTextField hoursPerWeekTextField;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField lastNameTextField;
private javax.swing.ButtonGroup partOrFullTimeButtonGroup;
private javax.swing.JRadioButton partTimeRadioButton;
private javax.swing.JLabel weeksPerYearLabel;
private javax.swing.JTextField weeksPerYearTextField;
private javax.swing.JComboBox<String> workLocationComboBox;
// End of variables declaration//GEN-END:variables
}