-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAthleteSearchGUI.java
More file actions
336 lines (310 loc) · 15.5 KB
/
AthleteSearchGUI.java
File metadata and controls
336 lines (310 loc) · 15.5 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
package PAT;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/*
adminSearchGUI class
Used as interface for the user to find the athlete in the database they are looking for
*/
public class AthleteSearchGUI extends javax.swing.JFrame {
public String foundID = ""; //variable to store the found Athlete's ID
public String userType =""; //The type of the current user
public String userWelcome = "";
Athlete ath = new Athlete();
/*
Constructor Method
Used when a new instance of the AthleteSearchGUI is created
@parameters: String userType, String user welcome message
@return: none
*/
public AthleteSearchGUI(String _userType, String _userWelcome) {
userType = _userType;
userWelcome = _userWelcome;
initComponents();
}
/**
* 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();
btnAthHelp = new javax.swing.JButton();
lblProgramName = new javax.swing.JLabel();
txtFieldNameSearch = new javax.swing.JTextField();
btnFind = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tblFoundAthletes = new javax.swing.JTable();
txtFieldSearchID = new javax.swing.JTextField();
lblAthID = new javax.swing.JLabel();
btnSelect = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnBack.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
btnBack.setText("BACK");
btnBack.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
btnBack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBackActionPerformed(evt);
}
});
btnAthHelp.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
btnAthHelp.setText("Help");
btnAthHelp.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
btnAthHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAthHelpActionPerformed(evt);
}
});
lblProgramName.setBackground(new java.awt.Color(255, 255, 255));
lblProgramName.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
lblProgramName.setText("Athlete Search");
lblProgramName.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
txtFieldNameSearch.setText("Enter Name Here");
txtFieldNameSearch.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
txtFieldNameSearchMouseClicked(evt);
}
});
btnFind.setText("Find");
btnFind.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFindActionPerformed(evt);
}
});
tblFoundAthletes.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"AthleteID", "Name", "Surname", "Grade"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
tblFoundAthletes.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblFoundAthletesMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tblFoundAthletes);
txtFieldSearchID.setEditable(false);
txtFieldSearchID.setBackground(new java.awt.Color(255, 255, 255));
lblAthID.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
lblAthID.setText("ID:");
btnSelect.setText("Select");
btnSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSelectActionPerformed(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()
.addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(60, 60, 60)
.addComponent(lblProgramName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
.addComponent(btnAthHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(lblAthID)
.addGap(72, 72, 72)
.addComponent(txtFieldSearchID, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(125, 125, 125))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(82, 82, 82))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(105, 105, 105)
.addComponent(txtFieldNameSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(74, 74, 74)
.addComponent(btnFind, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(204, 204, 204)
.addComponent(btnSelect)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProgramName, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.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))
.addGap(47, 47, 47)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtFieldNameSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnFind))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtFieldSearchID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAthID))
.addGap(18, 18, 18)
.addComponent(btnSelect)
.addContainerGap(29, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/*
Method of the Back Button
Opens an instance of the AthleteGUI class and then closes the AthleteSearchGUI class
*/
private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
AthleteGUI ath = new AthleteGUI(userType, userWelcome);
ath.setVisible(true);
dispose();
}//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 txtFieldNameSearchMouseClicked
Clears the existing text when the user clicks on the text field
*/
private void txtFieldNameSearchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtFieldNameSearchMouseClicked
txtFieldNameSearch.setText("");
}//GEN-LAST:event_txtFieldNameSearchMouseClicked
/*
Method of the Find button
Updates the table with Athletes that match the name provided as input
*/
private void btnFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindActionPerformed
String name = txtFieldNameSearch.getText(); //get name the user provides
updateSearchTable(name); //populate the table with matches
}//GEN-LAST:event_btnFindActionPerformed
/*
Method tblFoundAthletesMouseClicked
Loads the ID of the athlete selected into the text Field
*/
private void tblFoundAthletesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFoundAthletesMouseClicked
int row = tblFoundAthletes.rowAtPoint(evt.getPoint()); //check row position of athlete selected
//Populate text field with athlete ID
txtFieldSearchID.setText((String)tblFoundAthletes.getValueAt(row, 0));
}//GEN-LAST:event_tblFoundAthletesMouseClicked
/*
Method of the Select Button
Sends the ID of the found Athlete back to the AthleteGUI so it can be loaded into the data
fields there
*/
private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectActionPerformed
if(txtFieldSearchID.getText().isEmpty() == false){
foundID = txtFieldSearchID.getText();
AthleteGUI ath = new AthleteGUI(userType, userWelcome, foundID);
ath.setVisible(true);
dispose();
}else{
//Advise user to select an Athlete first
JOptionPane.showMessageDialog(null, "No Athlete is selected. Please select an athlete.");
}
}//GEN-LAST:event_btnSelectActionPerformed
/**
* @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(AthleteSearchGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AthleteSearchGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AthleteSearchGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AthleteSearchGUI.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 AthleteSearchGUI("","").setVisible(true);
}
});
}
/*
Method UpdateSearchTable
Inserts all the Athlete's that match the input name into the table
@parameters: String name provided by the user
@return: none
*/
private void updateSearchTable(String name){
clearTable(); //clear table of existing data
try {
ResultSet rs = ath.findAthlete(name); //get athletes that match name
while(rs.next()){
//Extract athlete's from resultset
String ID = rs.getString("AthleteID");
String _name = rs.getString("athName");
String sName = rs.getString("athSurname");
String athGrade = rs.getString("athGrade");
String data[] = {ID, _name, sName,athGrade};
DefaultTableModel model = (DefaultTableModel)tblFoundAthletes.getModel();
//Enter Athlete's into Table
model.addRow(data);
}
} catch (SQLException ex) {
Logger.getLogger(AthleteSearchGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
/*
Method clearTable
Clears the table of the current information it holds
*/
private void clearTable(){
DefaultTableModel model = (DefaultTableModel)tblFoundAthletes.getModel();
while(model.getRowCount()> 0){
model.removeRow(0);
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAthHelp;
private javax.swing.JButton btnBack;
private javax.swing.JButton btnFind;
private javax.swing.JButton btnSelect;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblAthID;
private javax.swing.JLabel lblProgramName;
private javax.swing.JTable tblFoundAthletes;
private javax.swing.JTextField txtFieldNameSearch;
private javax.swing.JTextField txtFieldSearchID;
// End of variables declaration//GEN-END:variables
}