· 10 years ago · Sep 26, 2016, 07:40 AM
1package view;
2
3import javax.swing.ImageIcon;
4import javax.swing.JButton;
5import javax.swing.JComboBox;
6import javax.swing.JFrame;
7import javax.swing.JLabel;
8import javax.swing.JOptionPane;
9import javax.swing.JPanel;
10import javax.swing.JScrollPane;
11import javax.swing.JTabbedPane;
12import javax.swing.JTable;
13import javax.swing.JTextField;
14import javax.swing.JTextPane;
15import javax.swing.UIManager;
16import javax.swing.table.DefaultTableModel;
17
18import java.awt.BorderLayout;
19import java.awt.EventQueue;
20import java.awt.Font;
21import java.awt.Image;
22import java.awt.event.ActionEvent;
23import java.awt.event.ActionListener;
24
25import java.sql.ResultSet;
26import java.sql.ResultSetMetaData;
27import java.sql.SQLException;
28
29import java.text.DecimalFormat;
30import java.util.Vector;
31
32
33import controller.Controller;
34
35public class Gui {
36
37 private JFrame frmOurSchoolSystem;
38 private JTextField textField_mainC_ccode;
39 private JTextField textField_addC_ccode;
40 private JTextField textField_addC_cname;
41 private JTextField textField_addC_cpoint;
42 private JTextField textField_mainS_spnr;
43 private JTextField textField_addS_spnr;
44 private JTextField textField_addS_sname;
45 private JTextField textField_showAddGradeS_spnr;
46 private JTextField textField_showAddGradeS_ccode;
47 private JTextField textField_mainC_percent_of_aGrade;
48
49 private JTable table_mainC_are_studing;
50 private JTable table_mainC_have_studied;
51 private JTable table_mainC_info_Course;
52 private JTable table_mainS_aboutS;
53 private JTable table_mainS_allC;
54 private JTable table_mainS_studyingC;
55 private JTable table_troughflowC;
56 private JTable table_showAddGradeS_result;
57 private JScrollPane scrolltable_mainC_info_Course;
58 private JScrollPane scrolltable_mainC_are_studying;
59
60 static Controller controller = new Controller();
61
62 private JTable table_viewAllS;
63 private JTable table_viewAllC;
64
65
66 /*------------------------LAUNCH THE APPLICATION--------------------------*/
67 public static void main(String[] args) {
68 EventQueue.invokeLater(new Runnable() {
69 public void run() {
70 try {
71 Gui window = new Gui();
72 window.frmOurSchoolSystem.setVisible(true);
73 } catch (Exception e) {
74 e.printStackTrace();
75 }
76 }
77 });
78 }
79
80 /*------------------------CREATE THE APPLICATION---------------------------*/
81 public Gui() {
82 initialize();
83 }
84
85 /*------------------INITIALIZE THE CONTENTS OF THE FRAME-------------------*/
86 private void initialize() {
87
88 frmOurSchoolSystem = new JFrame();
89 frmOurSchoolSystem.setTitle("SCHOOL SYSTEM");
90 frmOurSchoolSystem.setBounds(100, 100, 950, 500);
91 frmOurSchoolSystem.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
92 frmOurSchoolSystem.getContentPane().setLayout(new BorderLayout(0, 0));
93
94 JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
95 tabbedPane.setFont(new Font("Tahoma", Font.BOLD, 12));
96 frmOurSchoolSystem.getContentPane().add(tabbedPane, BorderLayout.CENTER);
97
98 /* -------------------------------------------------------------------------------------------------------------------- */
99 /* -----------------------------------------------COURSE TAB ---------------------------------------------------------- */
100 /* -------------------------------------------------------------------------------------------------------------------- */
101 JPanel panelCourse = new JPanel();
102 panelCourse.setToolTipText("");
103 tabbedPane.addTab(" Course ", null, panelCourse, null);
104 panelCourse.setLayout(new BorderLayout(0, 0));
105
106 JTabbedPane tabbedPaneCourse = new JTabbedPane(JTabbedPane.TOP);
107 panelCourse.add(tabbedPaneCourse, BorderLayout.CENTER);
108
109 /*------------------------PANEL FOR COURSE-----------------------*/
110 JPanel panel_course_mainC = new JPanel();
111 tabbedPaneCourse.addTab("Main", null, panel_course_mainC, null);
112 panel_course_mainC.setLayout(null);
113
114 JTextPane txtpn_mainC_ccode = new JTextPane();
115 txtpn_mainC_ccode.setEditable(false);
116 txtpn_mainC_ccode.setFont(new Font("Tahoma", Font.PLAIN, 12));
117 txtpn_mainC_ccode.setBackground(UIManager.getColor("Panel.background"));
118 txtpn_mainC_ccode.setText("Course code");
119 txtpn_mainC_ccode.setBounds(36, 74, 86, 20);
120 panel_course_mainC.add(txtpn_mainC_ccode);
121
122 textField_mainC_ccode = new JTextField();
123 textField_mainC_ccode.setBounds(146, 74, 86, 20);
124 panel_course_mainC.add(textField_mainC_ccode);
125 textField_mainC_ccode.setColumns(10);
126
127
128 JButton btn_mainC_ccode_search = new JButton("Search");
129 btn_mainC_ccode_search.setFont(new Font("Tahoma", Font.PLAIN, 12));
130 btn_mainC_ccode_search.setBounds(266, 74, 99, 23);
131 panel_course_mainC.add(btn_mainC_ccode_search);
132
133
134 JButton btn_mainC_ccode_remove = new JButton("Remove this course");
135 btn_mainC_ccode_remove.setFont(new Font("Tahoma", Font.PLAIN, 12));
136 btn_mainC_ccode_remove.setBounds(36, 340, 365, 23);
137 panel_course_mainC.add(btn_mainC_ccode_remove);
138
139
140 JTextPane txtpn_mainC_percent_of_aGrade = new JTextPane();
141 txtpn_mainC_percent_of_aGrade.setEditable(false);
142 txtpn_mainC_percent_of_aGrade.setBackground(UIManager.getColor("Panel.background"));
143 txtpn_mainC_percent_of_aGrade.setText("The percentage of students who got an A at the course :");
144 txtpn_mainC_percent_of_aGrade.setFont(new Font("Tahoma", Font.PLAIN, 12));
145 txtpn_mainC_percent_of_aGrade.setBounds(36, 177, 195, 36);
146 panel_course_mainC.add(txtpn_mainC_percent_of_aGrade);
147
148
149 textField_mainC_percent_of_aGrade = new JTextField();
150 textField_mainC_percent_of_aGrade.setEditable(false);
151 textField_mainC_percent_of_aGrade.setBounds(241, 193, 38, 20);
152 panel_course_mainC.add(textField_mainC_percent_of_aGrade);
153 textField_mainC_percent_of_aGrade.setColumns(10);
154
155
156 JTextPane txtpn_mainC_info_Course = new JTextPane();
157 txtpn_mainC_info_Course.setEditable(false);
158 txtpn_mainC_info_Course.setBackground(UIManager.getColor("Panel.background"));
159 txtpn_mainC_info_Course.setFont(new Font("Tahoma", Font.PLAIN, 12));
160 txtpn_mainC_info_Course.setText("Information about the course");
161 txtpn_mainC_info_Course.setBounds(36, 271, 187, 20);
162 panel_course_mainC.add(txtpn_mainC_info_Course);
163
164 table_mainC_info_Course = new JTable();
165 table_mainC_info_Course.setEnabled(false);
166 scrolltable_mainC_info_Course = new JScrollPane(table_mainC_info_Course);
167 scrolltable_mainC_info_Course.setBounds(36, 291, 365, 43);
168 panel_course_mainC.add(scrolltable_mainC_info_Course);
169
170
171 table_mainC_are_studing = new JTable();
172 table_mainC_are_studing.setEnabled(false);
173 scrolltable_mainC_are_studying = new JScrollPane(table_mainC_are_studing);
174 scrolltable_mainC_are_studying.setBounds(476, 51, 411, 126);
175 panel_course_mainC.add(scrolltable_mainC_are_studying);
176
177 JTextPane txtpn_mainC_are_studying = new JTextPane();
178 txtpn_mainC_are_studying.setEditable(false);
179 txtpn_mainC_are_studying.setBackground(UIManager.getColor("Panel.background"));
180 txtpn_mainC_are_studying.setFont(new Font("Tahoma", Font.PLAIN, 12));
181 txtpn_mainC_are_studying.setText("Students that are studying");
182 txtpn_mainC_are_studying.setBounds(476, 29, 165, 20);
183 panel_course_mainC.add(txtpn_mainC_are_studying);
184
185
186 JScrollPane scrollPane_mainC_have_studied = new JScrollPane();
187 scrollPane_mainC_have_studied.setBounds(476, 231, 411, 135);
188 panel_course_mainC.add(scrollPane_mainC_have_studied);
189
190 table_mainC_have_studied = new JTable();
191 table_mainC_have_studied.setEnabled(false);
192 scrollPane_mainC_have_studied.setViewportView(table_mainC_have_studied);
193
194 JTextPane txtpn_mainC_have_studied = new JTextPane();
195 txtpn_mainC_have_studied.setEditable(false);
196 txtpn_mainC_have_studied.setBackground(UIManager.getColor("Panel.background"));
197 txtpn_mainC_have_studied.setFont(new Font("Tahoma", Font.PLAIN, 12));
198 txtpn_mainC_have_studied.setText("Students that have studied");
199 txtpn_mainC_have_studied.setBounds(476, 211, 175, 20);
200 panel_course_mainC.add(txtpn_mainC_have_studied);
201
202
203 JTextPane textPane = new JTextPane();
204 textPane.setFont(new Font("Tahoma", Font.PLAIN, 12));
205 textPane.setEditable(false);
206 textPane.setBackground(UIManager.getColor("Panel.background"));
207 textPane.setText("%");
208 textPane.setBounds(280, 193, 26, 20);
209 panel_course_mainC.add(textPane);
210
211 /*------------------------VIEW TAB UNDER COURSE-----------------------*/
212 JPanel panel_course_viewAll = new JPanel();
213 tabbedPaneCourse.addTab("View", null, panel_course_viewAll, null);
214 panel_course_viewAll.setLayout(null);
215
216 JScrollPane scrollPane_viewAllC = new JScrollPane();
217 scrollPane_viewAllC.setBounds(151, 84, 540, 240);
218 panel_course_viewAll.add(scrollPane_viewAllC);
219
220 table_viewAllC = new JTable();
221 table_viewAllC.setEnabled(false);
222 scrollPane_viewAllC.setViewportView(table_viewAllC);
223
224 JTextPane txtpn_viewAllC = new JTextPane();
225 txtpn_viewAllC.setEditable(false);
226 txtpn_viewAllC.setBackground(UIManager.getColor("Panel.background"));
227 txtpn_viewAllC.setFont(new Font("Tahoma", Font.PLAIN, 12));
228 txtpn_viewAllC.setText("Views all courses");
229 txtpn_viewAllC.setBounds(151, 61, 160, 20);
230 panel_course_viewAll.add(txtpn_viewAllC);
231
232 JButton btn_viewAllC_update = new JButton("Update");
233 btn_viewAllC_update.setFont(new Font("Tahoma", Font.PLAIN, 12));
234 btn_viewAllC_update.setBounds(151, 333, 538, 23);
235 panel_course_viewAll.add(btn_viewAllC_update);
236
237 /*------------------------ADD COURSE TAB-----------------------*/
238 JPanel panel_course_addC = new JPanel();
239 tabbedPaneCourse.addTab("Add course", null, panel_course_addC, null);
240 panel_course_addC.setLayout(null);
241
242 JTextPane txtpn_addC_ccode = new JTextPane();
243 txtpn_addC_ccode.setEditable(false);
244 txtpn_addC_ccode.setFont(new Font("Tahoma", Font.PLAIN, 12));
245 txtpn_addC_ccode.setBackground(UIManager.getColor("Panel.background"));
246 txtpn_addC_ccode.setText("Course code");
247 txtpn_addC_ccode.setBounds(47, 92, 101, 20);
248 panel_course_addC.add(txtpn_addC_ccode);
249
250 textField_addC_ccode = new JTextField();
251 textField_addC_ccode.setBounds(172, 92, 140, 20);
252 panel_course_addC.add(textField_addC_ccode);
253 textField_addC_ccode.setColumns(10);
254
255 JTextPane txtpn_addC_cname = new JTextPane();
256 txtpn_addC_cname.setEditable(false);
257 txtpn_addC_cname.setFont(new Font("Tahoma", Font.PLAIN, 12));
258 txtpn_addC_cname.setBackground(UIManager.getColor("Panel.background"));
259 txtpn_addC_cname.setText("Course name");
260 txtpn_addC_cname.setBounds(47, 138, 101, 20);
261 panel_course_addC.add(txtpn_addC_cname);
262
263 textField_addC_cname = new JTextField();
264 textField_addC_cname.setBounds(172, 138, 140, 20);
265 panel_course_addC.add(textField_addC_cname);
266 textField_addC_cname.setColumns(10);
267
268 JTextPane txtpn_addC_cpoint = new JTextPane();
269 txtpn_addC_cpoint.setEditable(false);
270 txtpn_addC_cpoint.setFont(new Font("Tahoma", Font.PLAIN, 12));
271 txtpn_addC_cpoint.setBackground(UIManager.getColor("Panel.background"));
272 txtpn_addC_cpoint.setText("Course points");
273 txtpn_addC_cpoint.setBounds(47, 188, 101, 20);
274 panel_course_addC.add(txtpn_addC_cpoint);
275
276 textField_addC_cpoint = new JTextField();
277 textField_addC_cpoint.setBounds(172, 188, 140, 20);
278 panel_course_addC.add(textField_addC_cpoint);
279 textField_addC_cpoint.setColumns(10);
280
281 JButton btn_addC_course = new JButton("Add");
282 btn_addC_course.setBounds(194, 234, 89, 23);
283 panel_course_addC.add(btn_addC_course);
284
285 /*------------------------THE PICTURE UNDER ADD COURSE TAB-----------------------*/
286 JLabel lbl_addC_img = new JLabel("");
287 Image img = new ImageIcon (this.getClass(). getResource("/logo_course.png")). getImage();
288
289 JButton btn_addC_clear = new JButton("Clear fields");
290 btn_addC_clear.setBounds(10, 370, 101, 23);
291 panel_course_addC.add(btn_addC_clear);
292 lbl_addC_img.setIcon (new ImageIcon (img));
293 lbl_addC_img.setBounds(397, 0, 411, 394);
294 panel_course_addC.add(lbl_addC_img);
295
296 JPanel panel_course_troughflowC = new JPanel();
297 tabbedPaneCourse.addTab("Troughflow", null, panel_course_troughflowC, null);
298 panel_course_troughflowC.setLayout(null);
299
300 JScrollPane scrollPane_troughflowC = new JScrollPane();
301 scrollPane_troughflowC.setBounds(139, 133, 592, 115);
302 panel_course_troughflowC.add(scrollPane_troughflowC);
303
304 table_troughflowC = new JTable();
305 table_troughflowC.setEnabled(false);
306 scrollPane_troughflowC.setViewportView(table_troughflowC);
307
308 JTextPane txtpn_troughflowC = new JTextPane();
309 txtpn_troughflowC.setEditable(false);
310 txtpn_troughflowC.setBackground(UIManager.getColor("Panel.background"));
311 txtpn_troughflowC.setFont(new Font("Tahoma", Font.PLAIN, 12));
312 txtpn_troughflowC.setText("Show top 5 course(s) with the highest throughflow");
313 txtpn_troughflowC.setBounds(139, 104, 336, 27);
314 panel_course_troughflowC.add(txtpn_troughflowC);
315
316 /* -------------------------------------------------------------------------------------------------------------------- */
317 /* -----------------------------------------------STUDENT TAB --------------------------------------------------------- */
318 /* -------------------------------------------------------------------------------------------------------------------- */
319
320 /*------------------------PANEL FOR STUDENT-----------------------*/
321 JPanel panelStudent = new JPanel();
322 tabbedPane.addTab(" Student ", null, panelStudent, null);
323 panelStudent.setLayout(new BorderLayout(0, 0));
324
325 JTabbedPane tabbedPaneStudent = new JTabbedPane(JTabbedPane.TOP);
326 panelStudent.add(tabbedPaneStudent, BorderLayout.CENTER);
327
328 /*------------------------MAIN TAB UNDER STUDENT -----------------------*/
329 JPanel panel_student_mainS = new JPanel();
330 tabbedPaneStudent.addTab("Main", null, panel_student_mainS, null);
331 panel_student_mainS.setLayout(null);
332
333 JTextPane txtpn_mainS_spnr = new JTextPane();
334 txtpn_mainS_spnr.setEditable(false);
335 txtpn_mainS_spnr.setFont(new Font("Tahoma", Font.PLAIN, 12));
336 txtpn_mainS_spnr.setBackground(UIManager.getColor("Panel.background"));
337 txtpn_mainS_spnr.setText("Identity number");
338 txtpn_mainS_spnr.setBounds(34, 86, 107, 20);
339 panel_student_mainS.add(txtpn_mainS_spnr);
340
341 textField_mainS_spnr = new JTextField();
342 textField_mainS_spnr.setBounds(158, 86, 86, 20);
343 panel_student_mainS.add(textField_mainS_spnr);
344 textField_mainS_spnr.setColumns(10);
345
346 JButton btn_mainS_snpr_search = new JButton("Search");
347 btn_mainS_snpr_search.setFont(new Font("Tahoma", Font.PLAIN, 11));
348
349 btn_mainS_snpr_search.setBounds(268, 86, 89, 23);
350 panel_student_mainS.add(btn_mainS_snpr_search);
351
352 JButton btn_mainS_spnr_remove = new JButton("Remove this student");
353 btn_mainS_spnr_remove.setFont(new Font("Tahoma", Font.PLAIN, 11));
354
355 btn_mainS_spnr_remove.setBounds(34, 300, 366, 23);
356 panel_student_mainS.add(btn_mainS_spnr_remove);
357
358 JTextPane txtpn_mainS_aboutS = new JTextPane();
359 txtpn_mainS_aboutS.setEditable(false);
360 txtpn_mainS_aboutS.setFont(new Font("Tahoma", Font.PLAIN, 12));
361 txtpn_mainS_aboutS.setBackground(UIManager.getColor("Panel.background"));
362 txtpn_mainS_aboutS.setText("Details about the student");
363 txtpn_mainS_aboutS.setBounds(34, 232, 159, 20);
364 panel_student_mainS.add(txtpn_mainS_aboutS);
365
366 JScrollPane scrollPane_mainS_aboutS = new JScrollPane();
367 scrollPane_mainS_aboutS.setBounds(34, 253, 366, 42);
368 panel_student_mainS.add(scrollPane_mainS_aboutS);
369 table_mainS_aboutS = new JTable();
370 table_mainS_aboutS.setEnabled(false);
371 scrollPane_mainS_aboutS.setViewportView(table_mainS_aboutS);
372
373 JScrollPane scrollPane_mainS_allC = new JScrollPane();
374 scrollPane_mainS_allC.setBounds(504, 39, 385, 124);
375 panel_student_mainS.add(scrollPane_mainS_allC);
376
377 table_mainS_allC = new JTable();
378 scrollPane_mainS_allC.setViewportView(table_mainS_allC);
379
380 JTextPane txtpn_mainS_allC = new JTextPane();
381 txtpn_mainS_allC.setEditable(false);
382 txtpn_mainS_allC.setBackground(UIManager.getColor("Panel.background"));
383 txtpn_mainS_allC.setFont(new Font("Tahoma", Font.PLAIN, 12));
384 txtpn_mainS_allC.setText("All avalible courses");
385 txtpn_mainS_allC.setBounds(504, 21, 153, 17);
386 panel_student_mainS.add(txtpn_mainS_allC);
387
388 JButton btn_mainS_allC_add = new JButton("Add to selected course");
389 btn_mainS_allC_add.setFont(new Font("Tahoma", Font.PLAIN, 11));
390 btn_mainS_allC_add.setBounds(504, 167, 385, 23);
391 panel_student_mainS.add(btn_mainS_allC_add);
392
393 JScrollPane scrollPane_mainS_studyingC = new JScrollPane();
394 scrollPane_mainS_studyingC.setBounds(504, 240, 385, 113);
395 panel_student_mainS.add(scrollPane_mainS_studyingC);
396
397 table_mainS_studyingC = new JTable();
398 scrollPane_mainS_studyingC.setViewportView(table_mainS_studyingC);
399
400 JTextPane txtpn_mainS_studyingC = new JTextPane();
401 txtpn_mainS_studyingC.setEditable(false);
402 txtpn_mainS_studyingC.setBackground(UIManager.getColor("Panel.background"));
403 txtpn_mainS_studyingC.setFont(new Font("Tahoma", Font.PLAIN, 12));
404 txtpn_mainS_studyingC.setText("Course(s) this student is studying");
405 txtpn_mainS_studyingC.setBounds(504, 222, 220, 20);
406 panel_student_mainS.add(txtpn_mainS_studyingC);
407
408 JButton btnNewButton_mainS_studyingC_remove = new JButton("Remove from selected course");
409 btnNewButton_mainS_studyingC_remove.setFont(new Font("Tahoma", Font.PLAIN, 11));
410 btnNewButton_mainS_studyingC_remove.setBounds(504, 357, 385, 23);
411 panel_student_mainS.add(btnNewButton_mainS_studyingC_remove);
412
413 /*------------------------VIEW TAB UNDER STUDENT--------------------------*/
414 JPanel panel_student_viewAll = new JPanel();
415 tabbedPaneStudent.addTab("View", null, panel_student_viewAll, null);
416 panel_student_viewAll.setLayout(null);
417
418 JScrollPane scrollPane_viewAllS = new JScrollPane();
419 scrollPane_viewAllS.setBounds(146, 85, 540, 240);
420 panel_student_viewAll.add(scrollPane_viewAllS);
421
422 table_viewAllS = new JTable();
423 table_viewAllS.setEnabled(false);
424 scrollPane_viewAllS.setViewportView(table_viewAllS);
425
426 JTextPane txtpn_viewAllS = new JTextPane();
427 txtpn_viewAllS.setEditable(false);
428 txtpn_viewAllS.setBackground(UIManager.getColor("Panel.background"));
429 txtpn_viewAllS.setFont(new Font("Tahoma", Font.PLAIN, 12));
430 txtpn_viewAllS.setText("Views all students");
431 txtpn_viewAllS.setBounds(146, 59, 245, 20);
432 panel_student_viewAll.add(txtpn_viewAllS);
433
434 JButton btn_viewAllS_update = new JButton("Update");
435 btn_viewAllS_update.setFont(new Font("Tahoma", Font.PLAIN, 12));
436 btn_viewAllS_update.setBounds(146, 332, 538, 23);
437 panel_student_viewAll.add(btn_viewAllS_update);
438
439
440 /*------------------------FOR THE ADD STUDENT TAB UNDER STUDENT-----------------------*/
441 JPanel panel_student_addS = new JPanel();
442 tabbedPaneStudent.addTab("Add student", null, panel_student_addS, null);
443 panel_student_addS.setLayout(null);
444
445
446 JTextPane textpn_addS_spnr = new JTextPane();
447 textpn_addS_spnr.setEditable(false);
448 textpn_addS_spnr.setFont(new Font("Tahoma", Font.PLAIN, 12));
449 textpn_addS_spnr.setText("Identity number");
450 textpn_addS_spnr.setBackground(UIManager.getColor("Panel.background"));
451 textpn_addS_spnr.setBounds(53, 100, 109, 20);
452 panel_student_addS.add(textpn_addS_spnr);
453
454 textField_addS_spnr = new JTextField();
455 textField_addS_spnr.setBounds(172, 100, 140, 20);
456 panel_student_addS.add(textField_addS_spnr);
457 textField_addS_spnr.setColumns(10);
458
459 JTextPane txtpn_addS_sname = new JTextPane();
460 txtpn_addS_sname.setEditable(false);
461 txtpn_addS_sname.setBackground(UIManager.getColor("Panel.background"));
462 txtpn_addS_sname.setFont(new Font("Tahoma", Font.PLAIN, 12));
463 txtpn_addS_sname.setText("Name");
464 txtpn_addS_sname.setBounds(53, 156, 109, 20);
465 panel_student_addS.add(txtpn_addS_sname);
466
467 textField_addS_sname = new JTextField();
468 textField_addS_sname.setBounds(172, 156, 140, 20);
469 panel_student_addS.add(textField_addS_sname);
470 textField_addS_sname.setColumns(10);
471
472 JButton btn_addS_student = new JButton("Add");
473 btn_addS_student.setFont(new Font("Tahoma", Font.PLAIN, 12));
474 btn_addS_student.setBounds(193, 201, 89, 23);
475 panel_student_addS.add(btn_addS_student);
476
477 /*------------------------FOR THE PICTURE IN ADD STUDENT TAB-----------------------*/
478 JLabel lbl_addS_img2 = new JLabel("");
479 Image img2 = new ImageIcon (this.getClass(). getResource("/logo_student.png")). getImage();
480
481 JButton btn_addS_clear = new JButton("Clear fields");
482 btn_addS_clear.setBounds(10, 370, 103, 23);
483 panel_student_addS.add(btn_addS_clear);
484 lbl_addS_img2.setIcon (new ImageIcon (img2));
485 lbl_addS_img2.setBounds(383, 29, 470, 351);
486 panel_student_addS.add(lbl_addS_img2);
487
488 /*------------------------ADD GRADE/SHOW RESULT TAB UNDER STUDENT--------------------------*/
489 JPanel panel_student_showAddGradeS = new JPanel();
490 tabbedPaneStudent.addTab("Show result/ Add grade for finished course", null, panel_student_showAddGradeS, null);
491 panel_student_showAddGradeS.setLayout(null);
492
493 JTextPane txtpn_showAddGradeS_spnr = new JTextPane();
494 txtpn_showAddGradeS_spnr.setEditable(false);
495 txtpn_showAddGradeS_spnr.setFont(new Font("Tahoma", Font.PLAIN, 12));
496 txtpn_showAddGradeS_spnr.setBackground(UIManager.getColor("Panel.background"));
497 txtpn_showAddGradeS_spnr.setText("Identity number");
498 txtpn_showAddGradeS_spnr.setBounds(48, 82, 106, 20);
499 panel_student_showAddGradeS.add(txtpn_showAddGradeS_spnr);
500
501 textField_showAddGradeS_spnr = new JTextField();
502 textField_showAddGradeS_spnr.setBounds(164, 82, 86, 20);
503 panel_student_showAddGradeS.add(textField_showAddGradeS_spnr);
504 textField_showAddGradeS_spnr.setColumns(10);
505
506 JTextPane txtpn_showAddGradeS_ccode = new JTextPane();
507 txtpn_showAddGradeS_ccode.setEditable(false);
508 txtpn_showAddGradeS_ccode.setFont(new Font("Tahoma", Font.PLAIN, 12));
509 txtpn_showAddGradeS_ccode.setBackground(UIManager.getColor("Panel.background"));
510 txtpn_showAddGradeS_ccode.setText("Course code");
511 txtpn_showAddGradeS_ccode.setBounds(48, 131, 91, 20);
512 panel_student_showAddGradeS.add(txtpn_showAddGradeS_ccode);
513
514 textField_showAddGradeS_ccode = new JTextField();
515 textField_showAddGradeS_ccode.setBounds(164, 131, 86, 20);
516 panel_student_showAddGradeS.add(textField_showAddGradeS_ccode);
517 textField_showAddGradeS_ccode.setColumns(10);
518
519 JTextPane txtpn_showAddGradeS_grade = new JTextPane();
520 txtpn_showAddGradeS_grade.setEditable(false);
521 txtpn_showAddGradeS_grade.setFont(new Font("Tahoma", Font.PLAIN, 12));
522 txtpn_showAddGradeS_grade.setBackground(UIManager.getColor("Panel.background"));
523 txtpn_showAddGradeS_grade.setText("Grade");
524 txtpn_showAddGradeS_grade.setBounds(48, 185, 91, 20);
525 panel_student_showAddGradeS.add(txtpn_showAddGradeS_grade);
526
527 JComboBox<String> comboBox_showAddGradeS_grade = new JComboBox<String>();
528 comboBox_showAddGradeS_grade.setFont(new Font("Tahoma", Font.PLAIN, 12));
529 comboBox_showAddGradeS_grade.setBounds(164, 185, 86, 20);
530 comboBox_showAddGradeS_grade.addItem(null);
531 comboBox_showAddGradeS_grade.addItem("A");
532 comboBox_showAddGradeS_grade.addItem("B");
533 comboBox_showAddGradeS_grade.addItem("C");
534 comboBox_showAddGradeS_grade.addItem("D");
535 comboBox_showAddGradeS_grade.addItem("E");
536 comboBox_showAddGradeS_grade.addItem("U");
537 panel_student_showAddGradeS.add(comboBox_showAddGradeS_grade);
538
539 JButton btn_showAddGradeS_add = new JButton("Add grade");
540 btn_showAddGradeS_add.setFont(new Font("Tahoma", Font.PLAIN, 12));
541 btn_showAddGradeS_add.setBounds(164, 240, 116, 23);
542 panel_student_showAddGradeS.add(btn_showAddGradeS_add);
543
544 JButton btn_showAddGradeS_result = new JButton("Show result");
545 btn_showAddGradeS_result.setFont(new Font("Tahoma", Font.PLAIN, 12));
546 btn_showAddGradeS_result.setBounds(164, 285, 116, 23);
547 panel_student_showAddGradeS.add(btn_showAddGradeS_result);
548
549 JTextPane txtpn_showAddGradeS_result = new JTextPane();
550 txtpn_showAddGradeS_result.setEditable(false);
551 txtpn_showAddGradeS_result.setBackground(UIManager.getColor("Panel.background"));
552 txtpn_showAddGradeS_result.setFont(new Font("Tahoma", Font.PLAIN, 12));
553 txtpn_showAddGradeS_result.setText("Result for this student at this course");
554 txtpn_showAddGradeS_result.setBounds(408, 131, 231, 20);
555 panel_student_showAddGradeS.add(txtpn_showAddGradeS_result);
556
557 JScrollPane scrollPane_showAddGradeS_result = new JScrollPane();
558 scrollPane_showAddGradeS_result.setBounds(408, 157, 427, 42);
559 panel_student_showAddGradeS.add(scrollPane_showAddGradeS_result);
560
561 table_showAddGradeS_result = new JTable();
562 table_showAddGradeS_result.setEnabled(false);
563 scrollPane_showAddGradeS_result.setViewportView(table_showAddGradeS_result);
564
565 JButton btn_showAddGradeS_clear = new JButton("Clear fields");
566 btn_showAddGradeS_clear.setBounds(10, 370, 101, 23);
567 panel_student_showAddGradeS.add(btn_showAddGradeS_clear);
568
569 /*------------------------FOR UPDATE FLOWV BUTTON UNDER TROUGHFLOW UNDER COURSE--------------------------*/
570 JButton btn_UpdateFlow = new JButton("Update");
571 btn_UpdateFlow.setFont(new Font("Tahoma", Font.PLAIN, 12));
572 btn_UpdateFlow.setBounds(139, 259, 592, 23);
573 panel_course_troughflowC.add(btn_UpdateFlow);
574
575
576 /* -------------------------------------------------------------------------------------------------------------------- */
577 /* -----------------------------------------------ACTION LISTENERS ---------------------------------------------------- */
578 /* -------------------------------------------------------------------------------------------------------------------- */
579
580 /*------------------------FOR UPDATE UNDER VIEW ALL COURSES--------------------------*/
581 btn_viewAllC_update.addActionListener(new ActionListener() {
582 public void actionPerformed(ActionEvent e) {
583
584 try{
585 table_viewAllC.setModel(buildTableModel(controller.getAllCourses()));
586 } catch (SQLException se){
587 se.printStackTrace();
588 }
589 }
590 });
591
592 /*------------------------FOR UPDATE BUTTON UNDER VIEW ALL STUDENT-----------------------*/
593 btn_viewAllS_update.addActionListener(new ActionListener() {
594 public void actionPerformed(ActionEvent e) {
595
596 try{
597 table_viewAllS.setModel(buildTableModel(controller.getAllStudents()));
598 } catch (SQLException se){
599 se.printStackTrace();
600 }
601 }
602 });
603
604
605 /*------------------------FOR THE SEARCH COURSE BUTTON UNDER COURSE-----------------------*/
606
607 btn_mainC_ccode_search.addActionListener(new ActionListener() { // When clicked, search course...
608 public void actionPerformed(ActionEvent e) {
609
610 String ccode = textField_mainC_ccode.getText();
611
612 try {
613 if(ccode.equals("")){
614 JOptionPane.showMessageDialog(null, "The textfield is empty!");
615 }
616 else{
617 table_mainC_info_Course.setModel(buildTableModel(controller.getCourse(ccode)));
618 }
619 } catch (SQLException se) {
620 se.printStackTrace();
621 }
622 try{
623 double procentNr = controller.getProcentageOfA(ccode);
624 DecimalFormat df = new DecimalFormat("#0.0");
625 String dfDouble = df.format(procentNr);
626 textField_mainC_percent_of_aGrade.setText(dfDouble);
627 } catch (SQLException se){
628 se.printStackTrace();
629 textField_mainC_percent_of_aGrade.setText(null);
630 }
631 try{
632 table_mainC_are_studing.setModel(buildTableModel(controller.getStudentsNotReadyWithCourse(ccode)));
633 } catch (SQLException se){
634 se.printStackTrace();
635 }
636 try{
637 table_mainC_have_studied.setModel(buildTableModel(controller.getCourseResult(ccode)));
638 } catch (SQLException se){
639 se.printStackTrace();
640 }
641 }
642 });
643
644
645 /*------------------------FOR THE SEARCH STUDENT BUTTON UNDER STUDENT-----------------------*/
646 btn_mainS_snpr_search.addActionListener(new ActionListener() {
647
648 public void actionPerformed(ActionEvent e) {
649 String spnr = textField_mainS_spnr.getText();
650
651 try{
652 if(textField_mainS_spnr.getText().equals("")){
653 JOptionPane.showMessageDialog(null, "The textfield is empty!");
654 }
655 else{
656 table_mainS_aboutS.setModel(buildTableModel(controller.getStudent(spnr)));
657 }
658 }catch (SQLException se){
659 se.printStackTrace();
660 }
661 try{
662 table_mainS_allC.setModel(buildTableModel(controller.getAllCourses()));
663 } catch (SQLException se){
664 se.printStackTrace();
665 }
666 try{
667 table_mainS_studyingC.setModel(buildTableModel(controller.getCoursesStudentIsStudying(spnr)));
668 } catch (SQLException se){
669 se.printStackTrace();
670 }
671 }});
672
673 /*------------------------FOR THE REMOVE STUDENT BUTTON UNDER STUDENT-----------------------*/
674 btn_mainS_spnr_remove.addActionListener(new ActionListener() {
675
676 public void actionPerformed(ActionEvent e) {
677 }
678 });
679
680 /*------------------------FOR THE ADD COURSE BUTTON UNDER COURSE-----------------------*/
681 btn_addC_course.addActionListener(new ActionListener() {
682 public void actionPerformed(ActionEvent e){
683 try{
684 if(textField_addC_ccode.getText().equals("") || textField_addC_cname.getText().equals("") || textField_addC_cpoint.getText().equals("")){
685 JOptionPane.showMessageDialog(null, "All fields must be filled in!"); }
686 else{
687 int cpoint = Integer.parseInt(textField_addC_cpoint.getText());
688 int result = controller.addCourse(textField_addC_ccode.getText(), textField_addC_cname.getText(),cpoint);
689
690 if(result>0){
691 JOptionPane.showMessageDialog(null, "Course added successfully!");
692 textField_addC_ccode.setText(null);
693 textField_addC_cname.setText(null);
694 textField_addC_cpoint.setText(null);
695 }
696 else
697 JOptionPane.showMessageDialog(null, "Course could not be added");
698 }
699 }
700 catch (SQLException se){
701 se.printStackTrace();
702 JOptionPane.showMessageDialog(null, "Course could not be added");
703 }
704 }});
705
706
707 /*------------------------FOR THE ADD STUDENT BUTTON UNDER STUDENT-----------------------*/
708 btn_addS_student.addActionListener(new ActionListener() {
709 public void actionPerformed(ActionEvent e){
710 try{
711 if(textField_addS_spnr.getText().equals("") || textField_addS_sname.getText().equals("")){
712 JOptionPane.showMessageDialog(null, "All fields must be filled in!");
713 }else{
714 int result = controller.addStudent(textField_addS_spnr.getText(), textField_addS_sname.getText());
715 if(result>0){
716 JOptionPane.showMessageDialog(null, "Student added successfully!");
717 textField_addS_sname.setText(null);
718 textField_addS_spnr.setText(null);
719 }
720 else{
721 JOptionPane.showMessageDialog(null, "Student could not be added!");
722 }
723 }
724 }catch (SQLException se){
725 se.printStackTrace();
726 JOptionPane.showMessageDialog(null, "Student could not be added!");
727 }
728 }});
729
730 /*------------------------FOR THE ADD GRADE BUTTON UNDER STUDENT-----------------------*/
731 btn_showAddGradeS_add.addActionListener(new ActionListener() {
732 public void actionPerformed(ActionEvent e){
733 try{
734 if(textField_showAddGradeS_spnr.getText().equals("") || textField_showAddGradeS_ccode.getText().equals("") || comboBox_showAddGradeS_grade.getSelectedItem()==(null)){
735 JOptionPane.showMessageDialog(null, "Fields and combobox must be filled in!");
736 } else{
737 String grade = (String) comboBox_showAddGradeS_grade.getSelectedItem();
738 int result = controller.addStudied(textField_showAddGradeS_spnr.getText(), textField_showAddGradeS_ccode.getText(), grade);
739
740 if(result>0){
741 JOptionPane.showMessageDialog(null, "Grade successfully added!");
742 textField_showAddGradeS_spnr.setText(null);
743 textField_showAddGradeS_ccode.setText(null);
744 comboBox_showAddGradeS_grade.setSelectedItem(null);
745 }
746 else{
747 JOptionPane.showMessageDialog(null, "Grade successfully added!");
748 }
749 }
750 }catch (SQLException se){
751 se.printStackTrace();
752 JOptionPane.showMessageDialog(null, "Grade could not be added!");
753 }
754 }});
755
756 /*------------------------FOR THE ADD STUDENT TO COURSE BUTTON UNDER STUDENT-----------------------*/
757 btn_mainS_allC_add.addActionListener(new ActionListener() {
758 public void actionPerformed(ActionEvent e){
759
760 try{
761 int selectedRowCcode = table_mainS_allC.convertRowIndexToModel(table_mainS_allC.getSelectedRow());
762 int selectedColumnCcode = table_mainS_allC.convertColumnIndexToModel(0);
763
764 int selectedRowCpoint = table_mainS_allC.convertRowIndexToModel(table_mainS_allC.getSelectedRow());
765 int selectedColumnCpoint = table_mainS_allC.convertColumnIndexToModel(2);
766
767 String selectedCcode = (String)table_mainS_allC.getValueAt(selectedRowCcode, selectedColumnCcode);
768 int selectedCpoint = (int) table_mainS_allC.getValueAt(selectedRowCpoint, selectedColumnCpoint);
769
770 if(selectedCcode.equals(null)){
771 JOptionPane.showMessageDialog(null, "No row in selected!");
772 }
773 else if(controller.check45Points(textField_mainS_spnr.getText())+selectedCpoint>45){
774 JOptionPane.showMessageDialog(null, "Student is not aloud to take more then 45 points");
775 }
776 else{
777 controller.addStudies(textField_mainS_spnr.getText(), selectedCcode);
778 table_mainS_studyingC.setModel(buildTableModel(controller.getCoursesStudentIsStudying(textField_mainS_spnr.getText())));
779 }
780 }catch (SQLException se){
781 se.printStackTrace();
782 }
783 catch (Exception se){
784 se.printStackTrace();
785 }
786 }});
787
788 /*------------------------FOR SHOW RESULT BUTTON UNDER SHOWGRADE STUDENT-----------------------*/
789 btn_showAddGradeS_result.addActionListener(new ActionListener() {
790 public void actionPerformed(ActionEvent e) {
791 try{
792 String spnr = textField_showAddGradeS_spnr.getText();
793 String ccode = textField_showAddGradeS_ccode.getText();
794 table_showAddGradeS_result.setModel(buildTableModel(controller.getStudentResult(spnr, ccode)));
795
796 } catch (SQLException se){
797 se.printStackTrace();
798 }
799 }});
800
801 /*------------------------FOR THE REMOVE COURSE BUTTON UNDER COURSE-----------------------*/
802 btn_mainC_ccode_remove.addActionListener(new ActionListener() {
803 public void actionPerformed(ActionEvent e) {
804
805 try {
806 int result = controller.removeCourse(textField_mainC_ccode.getText());
807
808 if (result>0){
809 JOptionPane.showMessageDialog(null, "Course successfully removed!");
810 textField_mainC_ccode.setText(null);
811 table_mainC_are_studing.setModel(buildTableModel(controller.getStudentsNotReadyWithCourse(textField_mainC_ccode.getText())));
812 table_mainC_have_studied.setModel(buildTableModel(controller.getCourseResult(textField_mainC_ccode.getText())));
813 table_mainC_info_Course.setModel(buildTableModel(controller.getCourseResult(textField_mainC_ccode.getText())));
814 textField_mainC_percent_of_aGrade.setText(null);
815 }
816 else{
817 JOptionPane.showMessageDialog(null, "Course does not exists and can therefore not be removed!");
818 }
819 } catch (SQLException se) {
820 se.printStackTrace();
821 }
822 catch (Exception je){
823 je.printStackTrace();
824 }
825 }
826 });
827
828 /*------------------------FOR THE REMOVE STUDENT BUTTON UNDER STUDENT-----------------------*/
829 btn_mainS_spnr_remove.addActionListener(new ActionListener() {
830 public void actionPerformed(ActionEvent e) {
831
832 try{
833 int result = controller.removeStudent(textField_mainS_spnr.getText());
834
835 if(result>0){
836 controller.removeStudent(textField_mainS_spnr.getText());
837 JOptionPane.showMessageDialog(null, "Student successfully removed!");
838 textField_mainS_spnr.setText(null);
839 table_mainS_allC.setModel(buildTableModel(controller.getStudentsNotReadyWithCourse(textField_mainS_spnr.getText())));
840 table_mainS_studyingC.setModel(buildTableModel(controller.getCourseResult(textField_mainS_spnr.getText())));
841 table_mainS_aboutS.setModel(buildTableModel(controller.getCourseResult(textField_mainS_spnr.getText())));
842 }
843 else{
844 JOptionPane.showMessageDialog(null, "Student could not be removed");
845 table_mainS_allC.setModel(buildTableModel(controller.getStudentsNotReadyWithCourse(textField_mainS_spnr.getText())));
846 table_mainS_studyingC.setModel(buildTableModel(controller.getCourseResult(textField_mainS_spnr.getText())));
847 table_mainS_aboutS.setModel(buildTableModel(controller.getCourseResult(textField_mainS_spnr.getText())));
848 }
849 }
850 catch (SQLException se) {
851 JOptionPane.showMessageDialog(null, "something wrong fel!");
852 se.printStackTrace();
853 }
854 catch (Exception je){
855 je.printStackTrace();
856 }
857 }});
858
859 /*------------------------FOR THE REMOVE A STUDENT FROM A COURSE BUTTON UNDER STUDENT-----------------------*/
860 btnNewButton_mainS_studyingC_remove.addActionListener(new ActionListener() {
861 public void actionPerformed(ActionEvent e){
862
863 try{
864 int selectedRow = table_mainS_studyingC.convertRowIndexToModel(table_mainS_studyingC.getSelectedRow());
865 int selectedColumn = table_mainS_studyingC.convertColumnIndexToModel(0);
866
867 String selectedCcode = (String)table_mainS_studyingC.getValueAt(selectedRow, selectedColumn);
868 controller.removeStudentFromCourse(textField_mainS_spnr.getText(), selectedCcode);
869 }catch (SQLException se){
870 se.printStackTrace();
871 }try{
872 table_mainS_studyingC.setModel(buildTableModel(controller.getCoursesStudentIsStudying(textField_mainS_spnr.getText())));
873 } catch (SQLException se){
874 se.printStackTrace();
875 }
876 catch (Exception je){
877 je.printStackTrace();
878 }
879 }});
880
881 /*------------------------FOR THE CLEAR BUTTON UNDER ADD COURSE-----------------------*/
882 btn_addC_clear.addActionListener(new ActionListener() {
883 public void actionPerformed(ActionEvent e) {
884 textField_addC_ccode.setText(null);
885 textField_addC_cname.setText(null);
886 textField_addC_cpoint.setText(null);
887 }
888 });
889
890 /*------------------------FOR THE CLEAR BUTTON UNDER ADD STUDENT-----------------------*/
891 btn_addS_clear.addActionListener(new ActionListener() {
892 public void actionPerformed(ActionEvent e) {
893 textField_addS_spnr.setText(null);
894 textField_addS_sname.setText(null);
895 }
896 });
897
898 /*------------------------FOR THE CLEAR BUTTON UNDER ADD GRADE STUDENT-----------------------*/
899 btn_showAddGradeS_clear.addActionListener(new ActionListener() {
900 public void actionPerformed(ActionEvent e) {
901 textField_showAddGradeS_spnr.setText(null);
902 textField_showAddGradeS_ccode.setText(null);
903 comboBox_showAddGradeS_grade.setSelectedItem(null);
904 DefaultTableModel model = (DefaultTableModel) table_showAddGradeS_result.getModel();
905 model.setRowCount(0);
906 }
907 });
908
909 /*------------------------FOR THE UPDATE BUTTON UNDER THROUGHFLOW COURSE -----------------------*/
910 btn_UpdateFlow.addActionListener(new ActionListener() {
911 public void actionPerformed(ActionEvent e) {
912
913 try{
914 table_troughflowC.setModel(buildTableModel(controller.getHighestFlow()));
915 } catch (SQLException se){
916 se.printStackTrace();
917 }
918 catch (Exception je){
919 je.printStackTrace();
920 }
921 }
922 });
923 }
924
925 /* -------------------------------------------------------------------------------------------------------------------- */
926 /* --------------------------------------------------METHODS ---------------------------------------------------------- */
927 /* -------------------------------------------------------------------------------------------------------------------- */
928
929 /*------------------------CREATE A STANDARS TABLE TO DISPLAY RESULTSETS-----------------------*/
930 public static DefaultTableModel buildTableModel(ResultSet rs)
931
932 throws SQLException {
933 ResultSetMetaData metaData = rs.getMetaData();
934
935 /*------------------------NAMES OF COLUMNS-----------------------*/
936 Vector<String> columnNames = new Vector<String>();
937 int columnCount = metaData.getColumnCount();
938 for (int column = 1; column <= columnCount; column++) {
939 columnNames.add(metaData.getColumnName(column));
940 }
941
942 /*------------------------DATA OF THE TABLE-----------------------*/
943 Vector<Vector<Object>> data = new Vector<Vector<Object>>();
944
945 while (rs.next()) {
946 Vector<Object> vector = new Vector<Object>();
947 for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
948 vector.add(rs.getObject(columnIndex));
949 }
950 data.add(vector);
951 }
952 return new DefaultTableModel(data, columnNames);
953 }
954}