-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAthleteGUI.java
More file actions
746 lines (699 loc) · 40 KB
/
AthleteGUI.java
File metadata and controls
746 lines (699 loc) · 40 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
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
package PAT;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
/*
AthleteGUI class
Front end of the Athlete class and provides user with interface to interact with Athlete table in hostel database
*/
public class AthleteGUI extends javax.swing.JFrame {
String userWelcome = ""; //Contains welcom message used in main GUI
String userType = ""; //Contains type of the current user
Athlete ath = new Athlete(); //Instance of the Athlete class
ResultSet rs; //Stores the resultset of info received from the Athlete class
String foundID = ""; //Stores Athlete ID of the Athlete found in the AthleteSearchGUI
/*
Constructor Method #1
Used when Athlete is found in the search GUI and the found athlete is preloaded into the data fields
@parameters: String curent user's type, String User welcome message, String ID of the person found
@return: none
*/
public AthleteGUI(String _userType, String _userWelcome, String _foundID){
foundID = _foundID;
userType = _userType;
userWelcome = _userWelcome;
initComponents();
updateTable(); //Method to load data from the database into the table
insertFoundID(foundID); //Loads found Athlete into the data fields
}
/*
Constructor Method #2
Used when a new instance of the AthleteGUI is created without an athlete needed to be preloaded
@parameters: String userType, String user welcome message
@return: none
*/
public AthleteGUI(String _userType, String _userWelcome){
userType = _userType;
userWelcome = _userWelcome;
initComponents();
updateTable();
}
/**
* 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() {
btnBack = new javax.swing.JButton();
lblAthleteGUI = new javax.swing.JLabel();
btnAthHelp = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tblAthlete = new javax.swing.JTable();
lblAthID = new javax.swing.JLabel();
lblAthName = new javax.swing.JLabel();
lblAthSurname = new javax.swing.JLabel();
lblAthAge = new javax.swing.JLabel();
lblAthWeigth = new javax.swing.JLabel();
lblAthGrade = new javax.swing.JLabel();
lblathPos = new javax.swing.JLabel();
lblAthLength = new javax.swing.JLabel();
lblathMM = new javax.swing.JLabel();
txtFieldAthID = new javax.swing.JTextField();
txtFieldAthName = new javax.swing.JTextField();
txtFieldAthSurname = new javax.swing.JTextField();
cmbAthGrade = new javax.swing.JComboBox<>();
spinAthAge = new javax.swing.JSpinner();
sldrAthWeight = new javax.swing.JSlider();
txtFieldAthWeight = new javax.swing.JTextField();
spinAthPosition = new javax.swing.JSpinner();
btnPositionConverter = new javax.swing.JButton();
txtFieldAthPosition = new javax.swing.JTextField();
sldrAthLength = new javax.swing.JSlider();
txtFieldAthLength = new javax.swing.JTextField();
spinAthMissedMeals = new javax.swing.JSpinner();
btnClear = new javax.swing.JButton();
btnUpdate = new javax.swing.JButton();
btnInsert = new javax.swing.JButton();
btnDelete = new javax.swing.JButton();
btnSearch = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setLocation(new java.awt.Point(0, 0));
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
formMouseClicked(evt);
}
});
btnBack.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
btnBack.setText("BACK");
btnBack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBackActionPerformed(evt);
}
});
lblAthleteGUI.setBackground(new java.awt.Color(255, 255, 255));
lblAthleteGUI.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
lblAthleteGUI.setText(" Athlete");
btnAthHelp.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
btnAthHelp.setText("Help");
btnAthHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAthHelpActionPerformed(evt);
}
});
tblAthlete.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null}
},
new String [] {
"AthleteID", "athName", "athSurname", "athAge", "athGrade", "athWeight", "positionID", "athLength", "MissedMeals"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
tblAthlete.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblAthleteMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tblAthlete);
lblAthID.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthID.setText("ID:");
lblAthName.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthName.setText("Name:");
lblAthSurname.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthSurname.setText("Surname:");
lblAthAge.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthAge.setText("Age:");
lblAthWeigth.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthWeigth.setText("Weight:");
lblAthGrade.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthGrade.setText("Grade:");
lblathPos.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblathPos.setText("Position:");
lblAthLength.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthLength.setText("Length:");
lblathMM.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblathMM.setText("Missed Meals:");
txtFieldAthID.setEditable(false);
txtFieldAthID.setBackground(new java.awt.Color(255, 255, 255));
cmbAthGrade.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Grade 8", "Grade 9", "Grade 10", "Grade 11", "Grade 12" }));
spinAthAge.setModel(new javax.swing.SpinnerNumberModel(12, 12, 20, 1));
sldrAthWeight.setMaximum(150);
sldrAthWeight.setMinimum(30);
spinAthPosition.setModel(new javax.swing.SpinnerNumberModel(1, 1, 15, 1));
spinAthPosition.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spinAthPositionStateChanged(evt);
}
});
btnPositionConverter.setText("Convert");
btnPositionConverter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPositionConverterActionPerformed(evt);
}
});
txtFieldAthPosition.setEditable(false);
txtFieldAthPosition.setBackground(new java.awt.Color(255, 255, 255));
sldrAthLength.setMaximum(210);
sldrAthLength.setMinimum(130);
spinAthMissedMeals.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10, 1));
btnClear.setText("Clear");
btnClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnClearActionPerformed(evt);
}
});
btnUpdate.setText("Update");
btnUpdate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnUpdateActionPerformed(evt);
}
});
btnInsert.setText("Insert");
btnInsert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnInsertActionPerformed(evt);
}
});
btnDelete.setText("Remove");
btnDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeleteActionPerformed(evt);
}
});
btnSearch.setText("Search");
btnSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSearchActionPerformed(evt);
}
});
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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1)
.addGroup(layout.createSequentialGroup()
.addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lblAthleteGUI, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnAthHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(266, 266, 266)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnUpdate)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(lblathMM, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(507, 507, 507))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblAthLength, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblathPos, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthWeigth, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthGrade, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthAge, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthSurname, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthName, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthID, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cmbAthGrade, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtFieldAthName)
.addComponent(txtFieldAthID)
.addComponent(spinAthAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtFieldAthSurname))
.addGap(2, 2, 2))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(62, 62, 62)
.addComponent(spinAthPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addComponent(btnPositionConverter)
.addGap(18, 18, 18)
.addComponent(txtFieldAthPosition))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(46, 46, 46)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(sldrAthWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtFieldAthWeight, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(btnInsert)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnDelete))
.addComponent(sldrAthLength, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(spinAthMissedMeals, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtFieldAthLength, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSearch))))))
.addGap(193, 193, 193))))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnClear)
.addGap(374, 374, 374))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnAthHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthleteGUI, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblAthID)
.addComponent(txtFieldAthID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lblAthName))
.addComponent(txtFieldAthName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblAthSurname)
.addComponent(txtFieldAthSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblAthAge)
.addComponent(spinAthAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblAthGrade)
.addComponent(cmbAthGrade, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(17, 17, 17)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sldrAthWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthWeigth)
.addComponent(txtFieldAthWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblathPos)
.addComponent(spinAthPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnPositionConverter)
.addComponent(txtFieldAthPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblAthLength)
.addComponent(sldrAthLength, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtFieldAthLength, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblathMM)
.addComponent(spinAthMissedMeals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(5, 5, 5)
.addComponent(btnClear)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnUpdate)
.addComponent(btnInsert)
.addComponent(btnDelete)
.addComponent(btnSearch))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
/*
Method of the back button
Used to return to the Main GUI
*/
private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
dispose();
MainGUI mai = new MainGUI(userType, userWelcome);
mai.setVisible(true);
}//GEN-LAST:event_btnBackActionPerformed
/*
Method of the Help button
Opens the Help Text
*/
private void btnAthHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAthHelpActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btnAthHelpActionPerformed
/*
Method of the PositionConverter button
Gets the position of the selected Athlete in Integer form and generates
the name of the specified position and inserts it into the text field
*/
private void btnPositionConverterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPositionConverterActionPerformed
int pos = (Integer)spinAthPosition.getValue(); //get position value
try {
//populate data field with position name
txtFieldAthPosition.setText(ath.getPositionName(pos));
} catch (SQLException ex) {
Logger.getLogger(AthleteGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_btnPositionConverterActionPerformed
/*
Method tblathleteMouseClicked
Populates the data fields with the Athlete's info that has been selected
in the table by the user
*/
private void tblAthleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblAthleteMouseClicked
int row = tblAthlete.rowAtPoint(evt.getPoint()); //get row selected by the user
populateFields(row); //populate the data fields with info of that row
}//GEN-LAST:event_tblAthleteMouseClicked
/*
Method spinAthPositionStateChanged
When the Athlete's position in the data field changes the Position name is cleared
from the data field
*/
private void spinAthPositionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinAthPositionStateChanged
txtFieldAthPosition.setText("");
}//GEN-LAST:event_spinAthPositionStateChanged
//Ignore the following method
private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
}//GEN-LAST:event_formMouseClicked
/*
Method of the Clear button
Clears all the information in the data fields
*/
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed
clearFields();
}//GEN-LAST:event_btnClearActionPerformed
/*
Method of the Update button
Updates the information of the seleted Athlete with the info in the data fields
*/
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
//Check that an Athlete has been Selected
if(txtFieldAthID.getText().isEmpty() == false ){
//Check to see that the nae and surname fields aren't empty
if(txtFieldAthName.getText().isEmpty() == false && txtFieldAthSurname.getText().isEmpty() == false){
//Extract all the Athlete info from the data fields
String ID = txtFieldAthID.getText();
String name = txtFieldAthName.getText();
String surname = txtFieldAthSurname.getText();
int age = (Integer)spinAthAge.getValue();
int Grade = gradeConvertToInt((String)cmbAthGrade.getSelectedItem());
int weight = sldrAthWeight.getValue();
int position =(Integer)spinAthPosition.getValue();
int length = sldrAthLength.getValue();
int mm = (Integer)spinAthMissedMeals.getValue();
//Update the Athlete with the new info
ath.updateAthlete(ID, name, surname, age, Grade, weight, position, length, mm);
//Repopulate the table with the new information
updateTable();
//Clear all the data fields
clearFields();
//Notify user that the Athlete has been updated
JOptionPane.showMessageDialog(null, "Athlete has been updated");
}else{
//Advise user to enter a surname and/or name
JOptionPane.showMessageDialog(null, "Name and/or Surname fields are empty, please fill them.");
}
}else{
//Advise user to first select an Athlete
JOptionPane.showMessageDialog(null, "No Athlete has been selected");
}
}//GEN-LAST:event_btnUpdateActionPerformed
/*
Method of the Insert button
Inserts a new Athlete into the database
*/
private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertActionPerformed
//Checks that no current Athlete is selected
if(txtFieldAthID.getText().isEmpty() == true){
//Checks that the name and surname field aren't empty
if(txtFieldAthName.getText().isEmpty() == false && txtFieldAthSurname.getText().isEmpty() == false){
//Extract all the info from the data fields
String name = txtFieldAthName.getText();
String surname = txtFieldAthSurname.getText();
int age = (Integer)spinAthAge.getValue();
int Grade = gradeConvertToInt((String)cmbAthGrade.getSelectedItem());
int weight = sldrAthWeight.getValue();
int position =(Integer)spinAthPosition.getValue();
int length = sldrAthLength.getValue();
int mm = (Integer)spinAthMissedMeals.getValue();
//Insert new athlete with info from the data fields
ath.insertAthlete(name, surname, age, Grade, weight, position, length, mm);
//repopulate table with new info
updateTable();
//Clear the data fields of the current info
clearFields();
//Notify user that the new Athlete has been inserted
JOptionPane.showMessageDialog(null, "Athlete has been entered into the database.");
}else{
//Advise user to first fill the name and surname fields before continuing
JOptionPane.showMessageDialog(null, "Name and/or Surname fields are empty, please fill them.");
}
}else{
//Advise user to first clear fields so no current athlete is inserted again accidentally
JOptionPane.showMessageDialog(null, "Current Athlete selected. Clear fields first and then enter data.");
}
}//GEN-LAST:event_btnInsertActionPerformed
/*
Method of the delete button
Deletes the selected Athlete
*/
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
//Checks that an athlete is selected
if(txtFieldAthID.getText().isEmpty() == false){
//Gets the ID of the selected Athlete
String ID = txtFieldAthID.getText();
//Deletes the Athlete using the extracted ID
ath.deleteAthlete(ID);
//Repopulate table with new info
updateTable();
//Clear data field of current info
clearFields();
//Notify user that athlete has been removed
JOptionPane.showMessageDialog(null, "Athlete has been removed from the database.");
}else{
//Advise user to first select an athlete
JOptionPane.showMessageDialog(null, "No Athlete is selected. Select or Search for Athlete");
}
}//GEN-LAST:event_btnDeleteActionPerformed
/*
Method of the search button
Opens the AthleteSearchGUI so that the user can find the desired athlete
*/
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
String ID ="";
AthleteSearchGUI search = new AthleteSearchGUI(userType, userWelcome);
search.setVisible(true);
dispose();
}//GEN-LAST:event_btnSearchActionPerformed
/**
* @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(AthleteGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AthleteGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AthleteGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AthleteGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AthleteGUI("","").setVisible(true);
}
});
}
/*
Method updateTable
Used to insert all the new data into the table
@parameters: none
@return: none
*/
private void updateTable(){
clearTable(); //clear table's current info
try {
rs = ath.getAthleteInfo(); //get all the Athlete's information
while(rs.next()){
//Extract all the Athlete's data out of the resultset
String ID = rs.getString("AthleteID");
String name = rs.getString("athName");
String sName = rs.getString("athSurname");
String athAge = rs.getString("athAge");
String athGrade = rs.getString("athGrade");
String athWeight = rs.getString("athWeight");
String athPosition = rs.getString("positionID");
String athLength = rs.getString("athLength");
String MissedMeals = rs.getString("MissedMeals");
String data[] = {ID, name, sName, athAge, athGrade, athWeight, athPosition, athLength, MissedMeals};
DefaultTableModel model = (DefaultTableModel)tblAthlete.getModel();
//insert athlete's data into the GUI table
model.addRow(data);
}
} catch (SQLException ex) {
Logger.getLogger(AthleteGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
/*
Method clearTable
Method that removes all the current information from the table in the GUI
@parameters: none
@return: none
*/
private void clearTable(){
DefaultTableModel model = (DefaultTableModel)tblAthlete.getModel();
while(model.getRowCount()> 0){
model.removeRow(0);
}
}
/*
Method populateFields
Loads all the athlete's info into the data fields.
@parameters: int row in the table that has been selected
@return: none
*/
private void populateFields(int row){
//Gets data from the table and inserts it into the data fields
txtFieldAthID.setText((String)tblAthlete.getValueAt(row, 0));
txtFieldAthName.setText((String)tblAthlete.getValueAt(row, 1));
txtFieldAthSurname.setText((String)tblAthlete.getValueAt(row, 2));
spinAthAge.setValue(Integer.parseInt((String)tblAthlete.getValueAt(row, 3)));
String Grade = gradeConvertToString(Integer.parseInt((String)tblAthlete.getValueAt(row, 4)));
cmbAthGrade.setSelectedItem(Grade);
sldrAthWeight.setValue(Integer.parseInt((String)tblAthlete.getValueAt(row, 5)));
spinAthPosition.setValue(Integer.parseInt((String)tblAthlete.getValueAt(row, 6)));
sldrAthLength.setValue(Integer.parseInt((String)tblAthlete.getValueAt(row, 7)));
spinAthMissedMeals.setValue(Integer.parseInt((String)tblAthlete.getValueAt(row, 8)));
}
/*
Method clearFields
Clears all the data fields
@parameters: none
@return: none
*/
private void clearFields(){
//Clears every data field individually
txtFieldAthID.setText("");
txtFieldAthName.setText("");
txtFieldAthSurname.setText("");
spinAthAge.setValue(12);
cmbAthGrade.setSelectedItem("Grade 8");
sldrAthWeight.setValue(sldrAthWeight.getMinimum());
spinAthPosition.setValue(1);
sldrAthLength.setValue(sldrAthLength.getMinimum());
spinAthMissedMeals.setValue(0);
}
/*
Method gradeConvertToString
Converts the athlete's grade from Integer to String
@parameters: Integer athlete's grade
@return: string athlete's grade
*/
private String gradeConvertToString(int grd){
return "Grade " + grd;
}
/*
Method gradeConvertToInt
Converts the athlete's grade from String to Integer
@parameters: String athlete's grade
@return: Integer athlete's grade
*/
private int gradeConvertToInt(String grd){
int index = grd.indexOf(" "); //get index of the space in the string
int iGrade = 8;
if(grd.length() == 7){ //if the grade is single digits
iGrade = Integer.parseInt(grd.substring(index+1, index+2));
}else{ //if the grade is double digits e.g. 10
iGrade = Integer.parseInt(grd.substring(index+1, index+3));
}
return iGrade;
}
/*
Method insertFoundID
Inserts all the info of the found Athlete into the data fields
@parameters: the ID of the found Athlete in the AthleteSearchGUI
@return: none
*/
private void insertFoundID(String _foundID){
int row = 0;
boolean rowFound = false;
while(rowFound == false){
//check to see which row in the table matches the found ID
if(_foundID.equalsIgnoreCase((String)tblAthlete.getValueAt(row, 0))){
rowFound = true;
}else{
row++;
}
}
//populate the data fields with found Athlete's information
populateFields(row);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAthHelp;
private javax.swing.JButton btnBack;
private javax.swing.JButton btnClear;
private javax.swing.JButton btnDelete;
private javax.swing.JButton btnInsert;
private javax.swing.JButton btnPositionConverter;
private javax.swing.JButton btnSearch;
private javax.swing.JButton btnUpdate;
private javax.swing.JComboBox<String> cmbAthGrade;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblAthAge;
private javax.swing.JLabel lblAthGrade;
private javax.swing.JLabel lblAthID;
private javax.swing.JLabel lblAthLength;
private javax.swing.JLabel lblAthName;
private javax.swing.JLabel lblAthSurname;
private javax.swing.JLabel lblAthWeigth;
private javax.swing.JLabel lblAthleteGUI;
private javax.swing.JLabel lblathMM;
private javax.swing.JLabel lblathPos;
private javax.swing.JSlider sldrAthLength;
private javax.swing.JSlider sldrAthWeight;
private javax.swing.JSpinner spinAthAge;
private javax.swing.JSpinner spinAthMissedMeals;
private javax.swing.JSpinner spinAthPosition;
private javax.swing.JTable tblAthlete;
private javax.swing.JTextField txtFieldAthID;
private javax.swing.JTextField txtFieldAthLength;
private javax.swing.JTextField txtFieldAthName;
private javax.swing.JTextField txtFieldAthPosition;
private javax.swing.JTextField txtFieldAthSurname;
private javax.swing.JTextField txtFieldAthWeight;
// End of variables declaration//GEN-END:variables
}