forked from alexs2112/Scholarship-Thing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NominateStudent.java
129 lines (105 loc) · 4.1 KB
/
NominateStudent.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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class NominateStudent extends JFrame {
private static final long serialVersionUID = 1060623638149583738L;
private JPanel contentPane;
/**
* Create the frame.
*/
public NominateStudent(Data data, User user) {
//design elements
setTitle("University of Calgary Scholarship Application System | Nominate a Student");
setBounds(100, 100, 772, 500);
contentPane = new JPanel();
contentPane.setBackground(Color.ORANGE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
//An arraylist of all the scholarships and their associated data
ArrayList<Scholarship> scholarships = data.awards();
//An arrayList of the names of all the scholarships in the database
ArrayList<String> listOfNames = new ArrayList<String>();
AwardScholarships function = new AwardScholarships(data);
for (Scholarship award : scholarships) {
listOfNames.add(award.getScholName());
}
//An arraylist of all the students in the system and their associated data
ArrayList<User> users = data.users();
ArrayList<Applicant> allApplicants = new ArrayList<Applicant>();
for (User user1 : users) {
if (user1.role().contentEquals("student")) {
allApplicants.add((Applicant)user1);
}
}
//An arrayList of the names of all the students in the database
ArrayList<String> studentNames = new ArrayList<String>();
for (Applicant applicant : allApplicants) {
studentNames.add(applicant.firstName() + " " + applicant.lastName());
}
//An arrayList of the student IDs of all the students in the database
ArrayList<String> studentNumbers = new ArrayList<String>();
for (Applicant applicant : allApplicants) {
studentNumbers.add(applicant.id());
}
//display the names of all scholarships in a JList
JList scholList = new JList(listOfNames.toArray());
scholList.setBounds(414, 41, 318, 360);
contentPane.add(scholList);
//display the names of all the students in the system in a JList
JList studList = new JList(studentNames.toArray());
studList.setBounds(38, 41, 318, 360);
contentPane.add(studList);
//action handler for submit button
JButton btnNewButton = new JButton("Submit");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (studentNames.size() >= 1 && listOfNames.size() >= 1) {
if (scholList.isSelectionEmpty() || studList.isSelectionEmpty()) {
return;
} else {
//create new recommendation for selected student, of selected scholarship and current user
//save that recommendation to the applicants account
//save and close
String selectedStudent = studList.getSelectedValue().toString();
String selectedSchol = scholList.getSelectedValue().toString();
Recommendations recom = new Recommendations(user, scholarships.get(scholList.getSelectedIndex()));
Applicant appli = allApplicants.get(studList.getSelectedIndex());
users.remove(appli);
appli.addProfRec(recom);
users.add(appli);
data.saveData();
dispose();
}
}
}
});
btnNewButton.setBounds(615, 431, 117, 29);
contentPane.add(btnNewButton);
JLabel lblNewLabel = new JLabel("Please select a student: ");
lblNewLabel.setBounds(38, 6, 156, 29);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Select an award to nominate them for: ");
lblNewLabel_1.setBounds(414, 13, 318, 16);
contentPane.add(lblNewLabel_1);
//brings user to the previous window
JButton btnNewButton_1 = new JButton("Cancel");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnNewButton_1.setBounds(486, 431, 117, 29);
contentPane.add(btnNewButton_1);
}
}
;