forked from alexs2112/Scholarship-Thing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplyForAward.java
320 lines (272 loc) · 11.6 KB
/
ApplyForAward.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
import java.util.ArrayList;
import javax.swing.JFrame;
import java.text.DecimalFormat;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import java.awt.event.ActionListener;
import java.io.File;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import java.awt.Color;
public class ApplyForAward extends JFrame {
private static final long serialVersionUID = 1060623638149583738L;
private String filename = null;
private File transcript;
/**
* Create the frame.
*/
public ApplyForAward(Data data, User applicant, int index) {
//design elements
Applicant student = (Applicant)applicant;
setTitle("University of Calgary Scholarship Application System | Apply For An Award");
setBounds(100, 100, 853, 754);
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.ORANGE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Scholarship Application");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 24));
lblNewLabel.setBounds(28, 29, 600, 69);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("1. Your Information");
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 16));
lblNewLabel_1.setBounds(28, 94, 547, 35);
contentPane.add(lblNewLabel_1);
//Set up a label and autopopulate the text field for the first name
JLabel lblFirstName = new JLabel("First Name:");
lblFirstName.setBounds(25, 140, 96, 20);
JTextField txtFirstName = new JTextField();
txtFirstName.setText(student.firstName());
txtFirstName.setBounds(136, 139, 130, 22);
contentPane.add(lblFirstName);
contentPane.add(txtFirstName);
//Set up a label and autopopulate the text field for the last name
JLabel lblLastName = new JLabel("Last Name:");
lblLastName.setBounds(297, 140, 80, 20);
JTextField txtLastName = new JTextField();
txtLastName.setText(student.lastName());
txtLastName.setBounds(400,139, 130, 22);
contentPane.add(lblLastName);
contentPane.add(txtLastName);
//Do the same for the students ID
JLabel lblStudentId = new JLabel("Student ID:");
lblStudentId.setBounds(568, 140, 97, 20);
JTextField txtStudentId = new JTextField();
txtStudentId.setText(student.id());
txtStudentId.setBounds(670,139, 130, 22);
contentPane.add(lblStudentId);
contentPane.add(txtStudentId);
//Student Type
JLabel lblStudentType = new JLabel("Student Type:");
lblStudentType.setBounds(25, 178, 100, 20);
contentPane.add(lblStudentType);
JComboBox<String> typeBox = new JComboBox<String>();
typeBox.setModel(new DefaultComboBoxModel<String>(new String[] {"Undergraduate", "Graduate", "Post-Graduate"}));
typeBox.setSelectedItem(student.getStudentType());
typeBox.setBounds(136, 178, 130, 24);
contentPane.add(typeBox);
//Faculty
JLabel lblFaculty = new JLabel("Faculty:");
lblFaculty.setBounds(297, 178, 80, 20);
contentPane.add(lblFaculty);
JComboBox<String> facultyBox = new JComboBox<String>();
facultyBox.setModel(new DefaultComboBoxModel<String>(new String[] {"Arts", "Law", "Nursing", "Kinesiology", "Science", "Social Work", "Veterinary Medicine", "Medicine", "Business", "Engineering", "Education"}));
facultyBox.setSelectedItem(student.getFaculty());
facultyBox.setBounds(400, 178, 130, 24);
contentPane.add(facultyBox);
//Department
JLabel lblDepartment = new JLabel("Department:");
lblDepartment.setBounds(568, 180, 97, 20);
JTextField txtDepartment = new JTextField();
txtDepartment.setText(student.getDepartment());
txtDepartment.setBounds(670,179, 130, 22);
contentPane.add(lblDepartment);
contentPane.add(txtDepartment);
//GPA
final DecimalFormat df2= new DecimalFormat("#.##");
JLabel lblGPA = new JLabel("GPA:");
lblGPA.setBounds(25, 219, 80, 20);
JTextField txtGPA = new JTextField();
txtGPA.setText(String.valueOf( (df2.format(student.getGPA()))));
txtGPA.setBounds(136,219, 130, 22);
contentPane.add(lblGPA);
contentPane.add(txtGPA);
//Email
JLabel lblEmailAddress = new JLabel("Email:");
lblEmailAddress.setBounds(297, 219, 80, 20);
JTextField txtEmailAddress = new JTextField();
txtEmailAddress.setText(student.getEmail());
txtEmailAddress.setBounds(400,219, 130, 22);
contentPane.add(lblEmailAddress);
contentPane.add(txtEmailAddress);
//Action handler to update the applicants information if they have made any changes to the above text fields
JButton btnNewButton = new JButton("Update Info");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Updated Information Successful");
//Update student info
student.update(txtFirstName.getText(), txtLastName.getText(), txtStudentId.getText(),
typeBox.getSelectedItem().toString(), facultyBox.getSelectedItem().toString(),
txtDepartment.getText(), Double.valueOf(txtGPA.getText()), txtEmailAddress.getText());
//Save the data and reset the screen
dispose();
ApplyForAward appLog = new ApplyForAward(data, student, index);
appLog.setVisible(true);
data.saveData();
}
});
btnNewButton.setBounds(670, 219, 130, 22);
contentPane.add(btnNewButton);
JLabel lblNewLabel_4 = new JLabel("2. Choose Scholarship:");
lblNewLabel_4.setFont(new Font("Tahoma", Font.BOLD, 16));
lblNewLabel_4.setBounds(28, 310, 300, 16);
contentPane.add(lblNewLabel_4);
//Get a list of all available awards
ArrayList<Scholarship> awards = new ArrayList<Scholarship>();
for (Scholarship award : data.awards()) {
//Check every award in data, if it is not exclusive and inaccessible to the student, let them view it
if ( (award.faculty().equals(student.getFaculty()) || award.faculty().equals("None") ) &&
( award.studentType().equals(student.getStudentType()) || award.studentType().equals("None") ) &&
( award.department().equals(student.getDepartment()) || award.department().equals("None") ) ) {
awards.add(award);
}
}
String[] names = new String[awards.size()];
for (int i = 0; i < awards.size(); i++) {
names[i] = awards.get(i).getScholName();
}
int column1 = 280;
int row6 = 420;
JLabel lblName = new JLabel();
lblName.setBounds(309, 359, 300, 20);
lblName.setFont(new Font("Tahoma", Font.BOLD, 14));
contentPane.add(lblName);
JLabel lblDonor = new JLabel();
lblDonor.setBounds(309, 384, 300, 20);
lblDonor.setFont(new Font("Tahoma", Font.PLAIN, 14));
contentPane.add(lblDonor);
JLabel lblValue = new JLabel();
lblValue.setBounds(309, 407, 300, 20);
lblValue.setFont(new Font("Tahoma", Font.PLAIN, 14));
contentPane.add(lblValue);
JLabel lblReq = new JLabel();
lblReq.setBounds(309, 433, 300, 20);
lblReq.setFont(new Font("Tahoma", Font.PLAIN, 14));
contentPane.add(lblReq);
JLabel lblAmount = new JLabel();
lblAmount.setBounds(309, 456, 300, 20);
lblAmount.setFont(new Font("Tahoma", Font.PLAIN, 14));
contentPane.add(lblAmount);
JLabel lblApplied = new JLabel();
lblApplied.setBounds(309, 489, 300, 20);
lblApplied.setFont(new Font("Tahoma", Font.BOLD, 14));
contentPane.add(lblApplied);
JComboBox awardBox = new JComboBox();
awardBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Updates existing JLabels for award info
if (awards.size() >= 1) {
updateFields(awards.get(awardBox.getSelectedIndex()), contentPane, student, lblName, lblDonor, lblValue, lblReq, lblAmount, lblApplied);
}
}
});
awardBox.setModel(new DefaultComboBoxModel(names));
awardBox.setBounds(38, 336, 220, 24);
contentPane.add(awardBox);
if (awards.size() >= 1) {
awardBox.setSelectedIndex(index);
updateFields(awards.get(awardBox.getSelectedIndex()), contentPane, student, lblName, lblDonor, lblValue, lblReq, lblAmount, lblApplied);
}
JLabel lblNewLabel_5 = new JLabel("3. Upload Transcript(s)");
lblNewLabel_5.setFont(new Font("Tahoma", Font.BOLD, 16));
lblNewLabel_5.setBounds(28, 498, 250, 22);
contentPane.add(lblNewLabel_5);
JLabel messageLabel = new JLabel("");
messageLabel.setBounds(205, 539, 576, 16);
contentPane.add(messageLabel);
JButton btnNewButton_1 = new JButton("Upload files");
btnNewButton_1.setBounds(38, 536, 135, 25);
contentPane.add(btnNewButton_1);
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Images", "jpg", "png"));
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
filename = f.getAbsolutePath();
messageLabel.setText(filename);
transcript = chooser.getSelectedFile();
}
});
JLabel lblNewLabel_6 = new JLabel("4. Submit");
lblNewLabel_6.setFont(new Font("Tahoma", Font.BOLD, 16));
lblNewLabel_6.setBounds(28, 577, 250, 24);
contentPane.add(lblNewLabel_6);
JCheckBox checkBox = new JCheckBox("I agree to the terms and condition and declare that all infomation provided is correct");
checkBox.setBounds(28, 613, 1031, 35);
contentPane.add(checkBox);
JButton btnNewButton_2 = new JButton("Submit");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (checkBox.isSelected()) {
//Add the submission to the students applications
//Add the student to the scholarships applicants
//Close page and return to main menu
JOptionPane.showMessageDialog(null, "Submission Successful");
awards.get(awardBox.getSelectedIndex()).addApplicant(student);
student.addApplication(awards.get(awardBox.getSelectedIndex()));
student.addStudentFile(transcript);
data.saveData();
dispose();
} else {
JOptionPane.showMessageDialog(null, "Please Check the Terms and Conditions");
}
}
});
btnNewButton_2.setBounds(28, 657, 97, 25);
contentPane.add(btnNewButton_2);
JLabel lblNewLabel_2 = new JLabel("University of Calgary Scholarship Application System");
lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
lblNewLabel_2.setBounds(184, 6, 501, 35);
contentPane.add(lblNewLabel_2);
JButton btnNewButton_3 = new JButton("Cancel");
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnNewButton_3.setBounds(136, 655, 117, 29);
contentPane.add(btnNewButton_3);
}
//Updates JLabels for award info
public void updateFields(Scholarship award, JPanel contentPane, Applicant student, JLabel lblName, JLabel lblDonor, JLabel lblValue, JLabel lblReq, JLabel lblAmount, JLabel lblApplied) {
final DecimalFormat df2= new DecimalFormat("#.##");
String name = award.getScholName();
String donor = "Donor: " + award.getDonorName();
String value = "Value: $" + Integer.toString(award.getScholValue());
String req = "GPA Requirement: " + (df2.format(award.getReq()));
String amount = "Amount of Awards: " + Integer.toString(award.getTotalAmount());
String applied = "You have already applied for this award";
lblName.setText(name);
lblDonor.setText(donor);
lblValue.setText(value);
lblReq.setText(req);
lblAmount.setText(amount);
if (award.getApplicants().contains(student)) {
lblApplied.setText(applied);
}
else {
lblApplied.setText("");
}
}
}