· 10 years ago · Sep 26, 2016, 10:30 AM
1package Grupp25;
2
3import java.awt.BorderLayout;
4import java.awt.EventQueue;
5import java.awt.Font;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import java.awt.event.KeyAdapter;
9import java.awt.event.KeyEvent;
10import java.sql.SQLException;
11import java.util.ArrayList;
12
13import javax.swing.JButton;
14import javax.swing.JComboBox;
15import javax.swing.JFrame;
16import javax.swing.JLabel;
17import javax.swing.JOptionPane;
18import javax.swing.JPanel;
19import javax.swing.JScrollPane;
20import javax.swing.JSeparator;
21import javax.swing.JTabbedPane;
22import javax.swing.JTable;
23import javax.swing.JTextField;
24import javax.swing.UIManager;
25import javax.swing.event.ListSelectionEvent;
26import javax.swing.event.ListSelectionListener;
27import javax.swing.table.DefaultTableModel;
28
29public class MainView {
30
31 private Controller controller;
32 private JFrame frmStudentAdministration;
33 private JTextField textFieldSsid;
34 private JTextField textFieldSname;
35 private JTextField textFieldSaddress;
36 private JTextField textFieldRegSsid;
37 private JTextField textFieldRegCcode;
38 private JTextField textFieldGradeSsid;
39 private JTextField textFieldGradeCcode;
40 private JTextField textFieldSearchSsid;
41 private JTextField textFieldSearchSname;
42 private JTextField textFieldSearchAddress;
43 private JTextField textFieldSearchCcode;
44 private JTextField textFieldSearchCname;
45 private JTextField textFieldSearchCpoints;
46 private JTextField textFieldSearchListCcode;
47 private JTextField textFieldAdvCcode_1;
48 private JTextField textFieldAdvProcent;
49 private JTextField textFieldStudentFlow;
50 private JTextField textFieldSearchGradeSsid;
51 private JTextField textFieldSearchGradeCcode;
52 private JTextField textFieldCcode;
53 private JTextField textFieldCname;
54 private JTextField textFieldCpoints;
55 private JTextField textFieldGradeSemester;
56 private DefaultTableModel dataModel;
57 private DefaultTableModel dataModel_1;
58 private DefaultTableModel dataModel_2;
59 private DefaultTableModel dataModel_3;
60 private DefaultTableModel dataModel_4;
61 private JTable table;
62 private JTable table_1;
63 private JTable table_2;
64 private JTable table_3;
65 private JScrollPane scrollPane;
66 private JScrollPane scrollPane_1;
67 private JScrollPane scrollPane_2;
68 private JScrollPane scrollPane_3;
69
70 /**
71 * Launch app.
72 */
73 public static void main(String[] args) {
74 EventQueue.invokeLater(new Runnable() {
75 public void run() {
76 try {
77 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
78 MainView window = new MainView();
79 window.frmStudentAdministration.setVisible(true);
80 } catch (Exception e) {
81 e.printStackTrace();
82 }
83 }
84 });
85 }
86
87 /**
88 * Create the app.
89 */
90 public MainView() {
91 initialize();
92 this.controller = new Controller();
93 }
94
95 /**
96 .
97 */
98 private void initialize() {
99 frmStudentAdministration = new JFrame();
100 frmStudentAdministration.setTitle("Student administration");
101 frmStudentAdministration.setBounds(100, 100, 877, 731);
102 frmStudentAdministration.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
103
104 JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
105 frmStudentAdministration.getContentPane().add(tabbedPane, BorderLayout.CENTER);
106
107
108
109 dataModel_1 = new DefaultTableModel();
110
111 String[] headersReg = { "Course code", "Course name", "Course points" };
112 dataModel_1.setColumnIdentifiers(headersReg);
113
114 dataModel_2 = new DefaultTableModel();
115
116 String[] headersCourses = { "Course code", "Course name", "Semester" };
117 dataModel_2.setColumnIdentifiers(headersCourses);
118
119 JPanel panel = new JPanel();
120 tabbedPane.addTab("Start", null, panel, null);
121 panel.setLayout(null);
122
123 textFieldSsid = new JTextField();
124 textFieldSsid.setBounds(134, 42, 175, 20);
125 panel.add(textFieldSsid);
126 textFieldSsid.setColumns(10);
127
128 textFieldSname = new JTextField();
129 textFieldSname.setBounds(134, 73, 175, 20);
130 panel.add(textFieldSname);
131 textFieldSname.setColumns(10);
132
133 textFieldSaddress = new JTextField();
134 textFieldSaddress.setBounds(134, 104, 175, 20);
135 panel.add(textFieldSaddress);
136 textFieldSaddress.setColumns(10);
137
138 JLabel lblNewLabel = new JLabel("Student ID:");
139 lblNewLabel.setBounds(41, 45, 83, 14);
140 panel.add(lblNewLabel);
141
142 JLabel lblNewLabel_1 = new JLabel("Name:");
143 lblNewLabel_1.setBounds(41, 76, 83, 14);
144 panel.add(lblNewLabel_1);
145
146 JLabel lblNewLabel_2 = new JLabel("Address:");
147 lblNewLabel_2.setBounds(41, 107, 83, 14);
148 panel.add(lblNewLabel_2);
149
150 JLabel lblMessageStudent = new JLabel("Message: ");
151 lblMessageStudent.setFont(new Font("Tahoma", Font.PLAIN, 9));
152 lblMessageStudent.setBounds(41, 179, 274, 14);
153 panel.add(lblMessageStudent);
154
155 JButton btnAddStudent = new JButton("Add student");
156 btnAddStudent.addActionListener(new ActionListener() {
157 public void actionPerformed(ActionEvent e) {
158
159 String sSid = textFieldSsid.getText();
160 String sName = textFieldSname.getText();
161 String sAddress = textFieldSaddress.getText();
162
163 try {
164 if (textFieldSsid.getText().equals("") || textFieldSname.getText().equals("")) {
165 lblMessageStudent.setText("Message: Could not add student.");
166 } else {
167 controller.addStudent(sSid, sName, sAddress);
168 lblMessageStudent.setText("Message: Student added.");
169 textFieldSsid.setText(null);
170 textFieldSname.setText(null);
171 textFieldSaddress.setText(null);
172 }
173 } catch (Exception e1) {
174 lblMessageStudent.setText("Message: Could not add student. Already exists.");
175 }
176 }
177 });
178 btnAddStudent.setBounds(41, 145, 128, 23);
179 panel.add(btnAddStudent);
180
181 JButton btnRemoveStudent = new JButton("Remove student");
182 btnRemoveStudent.addActionListener(new ActionListener() {
183 public void actionPerformed(ActionEvent e) {
184 String sSid = textFieldSsid.getText();
185
186 try {
187 if (textFieldSsid.getText().equals("")) {
188 lblMessageStudent.setText("Message: Could not delete Student.");
189 } else {
190 controller.removeStudent(sSid);
191 lblMessageStudent.setText("Message: Student removed.");
192 textFieldSsid.setText(null);
193 textFieldSname.setText(null);
194 textFieldSaddress.setText(null);
195 }
196 } catch (Exception e1) {
197 lblMessageStudent.setText("Message: Could not remove student.");
198 }
199 }
200 });
201 btnRemoveStudent.setBounds(181, 145, 128, 23);
202 panel.add(btnRemoveStudent);
203
204 JLabel lblAddDelete = new JLabel("add / remove student");
205 lblAddDelete.setFont(new Font("Tahoma", Font.BOLD, 14));
206 lblAddDelete.setBounds(41, 11, 167, 20);
207 panel.add(lblAddDelete);
208
209 JLabel lblAddDelete_1 = new JLabel("add / remove course");
210 lblAddDelete_1.setFont(new Font("Tahoma", Font.BOLD, 14));
211 lblAddDelete_1.setBounds(41, 250, 203, 20);
212 panel.add(lblAddDelete_1);
213
214 textFieldCcode = new JTextField();
215 textFieldCcode.setBounds(127, 278, 175, 20);
216 panel.add(textFieldCcode);
217 textFieldCcode.setColumns(10);
218
219 JLabel lblCourseCode = new JLabel("Course code:");
220 lblCourseCode.setBounds(41, 281, 97, 14);
221 panel.add(lblCourseCode);
222
223 JLabel lblCourseName = new JLabel("Course name:");
224 lblCourseName.setBounds(41, 318, 97, 14);
225 panel.add(lblCourseName);
226
227 textFieldCname = new JTextField();
228 textFieldCname.setBounds(127, 315, 175, 20);
229 panel.add(textFieldCname);
230 textFieldCname.setColumns(10);
231
232 textFieldCpoints = new JTextField();
233 textFieldCpoints.setBounds(127, 346, 175, 20);
234 panel.add(textFieldCpoints);
235 textFieldCpoints.setColumns(10);
236
237 JLabel lblCoursePoints = new JLabel("Course points:");
238 lblCoursePoints.setBounds(41, 349, 86, 14);
239 panel.add(lblCoursePoints);
240
241 JLabel lblMessage_1 = new JLabel("Message:");
242 lblMessage_1.setFont(new Font("Tahoma", Font.PLAIN, 9));
243 lblMessage_1.setBounds(41, 428, 282, 14);
244 panel.add(lblMessage_1);
245
246 textFieldCpoints.addKeyListener(new KeyAdapter() {
247 public void keyTyped(KeyEvent e) {
248 char c = e.getKeyChar();
249 if (!(Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)) {
250 e.consume();
251 }
252 }
253 });
254
255 JButton btnAddCourse = new JButton("Add course");
256
257
258 btnAddCourse.addActionListener(new ActionListener() {
259 public void actionPerformed(ActionEvent e) {
260
261 String cCode = textFieldCcode.getText();
262 String cName = textFieldCname.getText();
263 String cPoints = textFieldCpoints.getText();
264 int cCp = 0;
265
266
267 if (!cPoints.equals("")) {
268 cCp = Integer.parseInt(cPoints);
269 }
270
271 try {
272 if (textFieldCcode.getText().equals("") || textFieldCpoints.getText().equals("")) {
273 lblMessage_1.setText("Message: Could not add course.");
274 } else {
275 controller.addCourse(cCode, cName, cCp);
276 lblMessage_1.setText("Message: Course added.");
277 textFieldCcode.setText(null);
278 textFieldCname.setText(null);
279 textFieldCpoints.setText(null);
280 }
281 } catch (Exception e1) {
282 lblMessage_1.setText("Message: Could not add course. Course already exsist.");
283 }
284
285 }
286 });
287 btnAddCourse.setBounds(41, 391, 128, 23);
288 panel.add(btnAddCourse);
289
290 JButton btnDeleteCurse = new JButton("Remove course");
291 btnDeleteCurse.addActionListener(new ActionListener() {
292 public void actionPerformed(ActionEvent e) {
293 String cCode = textFieldCcode.getText();
294
295 try {
296 if (textFieldCcode.getText().equals("")) {
297 lblMessage_1.setText("Message: Could not remove.");
298 } else {
299 controller.removeCourse(cCode);
300 lblMessage_1.setText("Message: Remove course.");
301 textFieldCcode.setText(null);
302 textFieldCname.setText(null);
303 textFieldCpoints.setText(null);
304 }
305 } catch (Exception e1) {
306 lblMessage_1.setText("Message: Could not remove course.");
307 }
308
309 }
310 });
311 btnDeleteCurse.setBounds(181, 391, 128, 23);
312 panel.add(btnDeleteCurse);
313 panel.setLayout(null);
314
315 textFieldRegSsid = new JTextField();
316 textFieldRegSsid.setBounds(410, 39, 97, 20);
317 panel.add(textFieldRegSsid);
318 textFieldRegSsid.setColumns(10);
319
320 textFieldRegCcode = new JTextField();
321 textFieldRegCcode.setEditable(false);
322 textFieldRegCcode.setBounds(748, 86, 86, 20);
323 panel.add(textFieldRegCcode);
324 textFieldRegCcode.setColumns(10);
325
326 JLabel lblNewLabel_3 = new JLabel("Student ID:");
327 lblNewLabel_3.setBounds(348, 42, 84, 14);
328 panel.add(lblNewLabel_3);
329
330 JLabel lblCourseCode_1 = new JLabel("Course code:");
331 lblCourseCode_1.setBounds(677, 89, 84, 14);
332 panel.add(lblCourseCode_1);
333
334 JLabel lblSemester = new JLabel("Semester:");
335 lblSemester.setBounds(677, 121, 84, 14);
336 panel.add(lblSemester);
337
338 JComboBox<String> comboBoxRegSemester = new JComboBox<String>();
339 comboBoxRegSemester.addItem("HT13");
340 comboBoxRegSemester.addItem("VT14");
341 comboBoxRegSemester.addItem("HT14");
342 comboBoxRegSemester.addItem("VT15");
343 comboBoxRegSemester.addItem("HT15");
344
345 comboBoxRegSemester.setBounds(748, 118, 86, 20);
346 panel.add(comboBoxRegSemester);
347
348 JLabel lblNewLabelInteraction = new JLabel("Message:");
349 lblNewLabelInteraction.setFont(new Font("Tahoma", Font.PLAIN, 9));
350 lblNewLabelInteraction.setBounds(679, 191, 376, 14);
351 panel.add(lblNewLabelInteraction);
352
353 JButton btnNewButtonRegStudying = new JButton("Apply");
354 btnNewButtonRegStudying.addActionListener(new ActionListener() {
355 public void actionPerformed(ActionEvent e) {
356 String sSid = textFieldRegSsid.getText();
357 String cCode = textFieldRegCcode.getText();
358 String semester = comboBoxRegSemester.getSelectedItem().toString();
359
360 try {
361 if( textFieldRegSsid.getText().equals("")){
362 lblNewLabelInteraction.setText("no student ID entered");
363 }
364 else{
365 controller.addStudentStudying(sSid, cCode, semester);
366 lblNewLabelInteraction.setText("stundent successfully added to course");
367 }
368 } catch (SQLException e1) {
369
370 e1.printStackTrace();
371
372 }
373
374 }
375
376 });
377 btnNewButtonRegStudying.setBounds(748, 158, 86, 22);
378 panel.add(btnNewButtonRegStudying);
379
380 JLabel lblAddingStudentTo = new JLabel("Add student to course");
381 lblAddingStudentTo.setFont(new Font("Tahoma", Font.BOLD, 14));
382 lblAddingStudentTo.setBounds(348, 11, 318, 20);
383 panel.add(lblAddingStudentTo);
384 table_1 = new JTable(dataModel_1);
385 scrollPane_1 = new JScrollPane(table_1);
386
387 scrollPane_1.setBounds(348, 88, 319, 138);
388 panel.add(scrollPane_1);
389
390 JButton btnPopulateCourse = new JButton("Fill list");
391 btnPopulateCourse.addActionListener(new ActionListener() {
392 public void actionPerformed(ActionEvent e) {
393 try {
394
395 dataModel_1.setRowCount(0);
396 ArrayList<Course> courseList = controller.getAllCourse();
397
398 for (Course c : courseList) {
399 String[] col = new String[3];
400 col[0] = c.getCcode();
401 col[1] = c.getCname();
402 String cPoints = Integer.toString(c.getCcp());
403 col[2] = cPoints;
404 dataModel_1.addRow(col);
405 }
406
407 } catch (SQLException e1) {
408 JOptionPane.showMessageDialog(null, "Could not populate list \n Error: " + e1);
409 }
410 }
411 });
412 btnPopulateCourse.setBounds(517, 38, 116, 23);
413 panel.add(btnPopulateCourse);
414
415 JLabel lblSelectACourse = new JLabel("V‰lj en kurs frÂn listan:");
416 lblSelectACourse.setBounds(348, 70, 212, 14);
417 panel.add(lblSelectACourse);
418
419 JSeparator separator = new JSeparator();
420 separator.setBounds(10, 237, 836, 2);
421 panel.add(separator);
422
423 table_1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
424 public void valueChanged(ListSelectionEvent event) {
425 if (table_1.getSelectedRow() >= 0) {
426 try {
427 textFieldRegCcode.setText(table_1.getValueAt(table_1.getSelectedRow(), 0).toString());
428 } catch (Exception e1) {
429 JOptionPane.showMessageDialog(null, "Something went wrong!");
430 }
431 }
432 }
433 });
434
435 textFieldGradeSsid = new JTextField();
436 textFieldGradeSsid.setBounds(424, 278, 97, 20);
437 panel.add(textFieldGradeSsid);
438 textFieldGradeSsid.setColumns(10);
439
440 JLabel lblStudentId = new JLabel("Student ID:");
441 lblStudentId.setBounds(348, 281, 85, 14);
442 panel.add(lblStudentId);
443
444 JLabel lblCourseCode_2 = new JLabel("Course code:");
445 lblCourseCode_2.setBounds(676, 349, 85, 14);
446 panel.add(lblCourseCode_2);
447
448 textFieldGradeCcode = new JTextField();
449 textFieldGradeCcode.setEditable(false);
450 textFieldGradeCcode.setBounds(748, 346, 86, 20);
451 panel.add(textFieldGradeCcode);
452 textFieldGradeCcode.setColumns(10);
453
454 JLabel lblGrade = new JLabel("Grade:");
455 lblGrade.setBounds(677, 442, 46, 14);
456 panel.add(lblGrade);
457
458 JComboBox<String> comboBoxGrade = new JComboBox<String>();
459 comboBoxGrade.addItem("A");
460 comboBoxGrade.addItem("B");
461 comboBoxGrade.addItem("C");
462 comboBoxGrade.addItem("D");
463 comboBoxGrade.addItem("E");
464 comboBoxGrade.addItem("U");
465
466 comboBoxGrade.setBounds(748, 439, 68, 20);
467 panel.add(comboBoxGrade);
468
469 JLabel lblMessageGrade = new JLabel("Message:");
470 lblMessageGrade.setFont(new Font("Tahoma", Font.PLAIN, 9));
471 lblMessageGrade.setBounds(348, 500, 351, 14);
472 panel.add(lblMessageGrade);
473
474 JButton btnApply = new JButton("Add grade");
475 btnApply.addActionListener(new ActionListener() {
476 public void actionPerformed(ActionEvent e) {
477 String sSid = textFieldGradeSsid.getText();
478 String cCode = textFieldGradeCcode.getText();
479 String semester = textFieldGradeSemester.getText();
480 String grade = comboBoxGrade.getSelectedItem().toString();
481
482 try {
483 if( textFieldGradeSsid.getText().equals("")){
484 lblMessageGrade.setText("no student ID entered");
485 }
486 else{
487 controller.addStudentStudied(sSid, cCode, semester,grade);
488 lblMessageGrade.setText("Grade successfully added to student");
489 }
490
491 } catch (SQLException e1) {
492
493 e1.printStackTrace();
494
495 }}
496 });
497 btnApply.setBounds(677, 483, 153, 23);
498 panel.add(btnApply);
499
500 JLabel lblSemester_1 = new JLabel("Semester:");
501 lblSemester_1.setBounds(677, 395, 85, 14);
502 panel.add(lblSemester_1);
503 table_2 = new JTable(dataModel_2);
504 scrollPane_2 = new JScrollPane(table_2);
505
506 scrollPane_2.setBounds(348, 348, 318, 138);
507 panel.add(scrollPane_2);
508
509 JButton btnPoulateCourses = new JButton("Sˆk/hitta kurs");
510 btnPoulateCourses.addActionListener(new ActionListener() {
511 public void actionPerformed(ActionEvent e) {
512 try {
513 dataModel_2.setRowCount(0);
514 textFieldGradeCcode.setText("");
515 textFieldGradeSemester.setText("");
516
517 String sSid = textFieldGradeSsid.getText();
518
519 ArrayList<Studying> courseList = controller.getStudentsCourse(sSid);
520
521 for (Studying c : courseList) {
522 String[] col = new String[3];
523 col[0] = c.getssid();
524 col[1] = c.getccode();
525 col[2] = c.getsemester();
526 dataModel_2.addRow(col);
527
528 }
529
530 } catch (SQLException e1) {
531 e1.printStackTrace();
532 JOptionPane.showMessageDialog(null, "Could not find course" + e1);
533 }
534
535 }
536 });
537
538 btnPoulateCourses.setBounds(538, 277, 128, 23);
539 panel.add(btnPoulateCourses);
540
541 table_2.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
542 public void valueChanged(ListSelectionEvent event) {
543 if (table_2.getSelectedRow() >= 0) {
544 try {
545 textFieldGradeCcode.setText(table_2.getValueAt(table_2.getSelectedRow(), 0).toString());
546 textFieldGradeSemester.setText(table_2.getValueAt(table_2.getSelectedRow(), 2).toString());
547 } catch (Exception e1) {
548 JOptionPane.showMessageDialog(null, "Something went wrong!");
549 }
550 }
551 }
552 });
553
554 textFieldGradeSemester = new JTextField();
555 textFieldGradeSemester.setEditable(false);
556 textFieldGradeSemester.setBounds(748, 392, 86, 20);
557 panel.add(textFieldGradeSemester);
558 textFieldGradeSemester.setColumns(10);
559
560 JLabel lblGiveStudentA = new JLabel("Manage student's courses");
561 lblGiveStudentA.setFont(new Font("Tahoma", Font.BOLD, 14));
562 lblGiveStudentA.setBounds(348, 250, 217, 20);
563 panel.add(lblGiveStudentA);
564
565 JButton btnRemoveFromCourse = new JButton("Remove from course");
566 btnRemoveFromCourse.addActionListener(new ActionListener() {
567 public void actionPerformed(ActionEvent e) {
568 String sSid = textFieldGradeSsid.getText();
569 String cCode = textFieldGradeCcode.getText();
570
571 try {
572 if (textFieldGradeSsid.getText().equals("") || textFieldGradeCcode.getText().equals("")) {
573 lblMessageGrade
574 .setText("Message: Student not removed since student ID or course code missing.");
575 } else {
576 controller.removeStudentFromStudying(sSid, cCode);
577 lblMessageGrade.setText("Message: Student removed from course.");
578 textFieldGradeCcode.setText(null);
579 textFieldGradeSemester.setText(null);
580 dataModel_2.setRowCount(0);
581
582 }
583 } catch (Exception e1) {
584 lblMessageGrade.setText("Message: No grade has been added.");
585 }
586
587 }
588 });
589 btnRemoveFromCourse.setBounds(677, 525, 153, 23);
590 panel.add(btnRemoveFromCourse);
591
592 JLabel lblSelectCourseFrom = new JLabel("Choose a course lis below please:");
593 lblSelectCourseFrom.setBounds(348, 318, 181, 14);
594 panel.add(lblSelectCourseFrom);
595
596 JPanel panel_4 = new JPanel();
597 tabbedPane.addTab("Search1", null, panel_4, null);
598 panel_4.setLayout(null);
599
600 JLabel lblStudentId_1 = new JLabel("Student ID:");
601 lblStudentId_1.setBounds(40, 67, 78, 14);
602 panel_4.add(lblStudentId_1);
603
604 textFieldSearchSsid = new JTextField();
605 textFieldSearchSsid.setBounds(148, 64, 175, 20);
606 panel_4.add(textFieldSearchSsid);
607 textFieldSearchSsid.setColumns(10);
608
609 textFieldSearchSname = new JTextField();
610 textFieldSearchSname.setEditable(false);
611 textFieldSearchSname.setBounds(148, 92, 175, 20);
612 panel_4.add(textFieldSearchSname);
613 textFieldSearchSname.setColumns(10);
614
615 textFieldSearchAddress = new JTextField();
616 textFieldSearchAddress.setEditable(false);
617 textFieldSearchAddress.setBounds(148, 120, 175, 20);
618 panel_4.add(textFieldSearchAddress);
619 textFieldSearchAddress.setColumns(10);
620
621 JLabel lblName = new JLabel("Name:");
622 lblName.setBounds(40, 95, 65, 14);
623 panel_4.add(lblName);
624
625 JLabel lblAddress = new JLabel("Address:");
626 lblAddress.setBounds(40, 123, 78, 14);
627 panel_4.add(lblAddress);
628
629 JLabel lblInfoSearch_1 = new JLabel("Message:");
630 lblInfoSearch_1.setFont(new Font("Tahoma", Font.PLAIN, 9));
631 lblInfoSearch_1.setBounds(40, 181, 360, 14);
632 panel_4.add(lblInfoSearch_1);
633
634 JButton btnSearchStudent = new JButton("Search");
635 btnSearchStudent.addActionListener(new ActionListener() {
636 public void actionPerformed(ActionEvent e) {
637 String sSid = textFieldSearchSsid.getText();
638 try {
639 if (textFieldSearchSsid.getText().equals("")) {
640 lblInfoSearch_1.setText("Message: No student ID entered.");
641 } else {
642 textFieldSearchSname.setText(controller.findStudent(sSid).getSname());
643 textFieldSearchAddress.setText(controller.findStudent(sSid).getSaddress());
644 lblInfoSearch_1.setText("Message: Showing student information.");
645 }
646 } catch (Exception e1) {
647 lblInfoSearch_1.setText("Message: Could not find student.");
648 }
649
650 }
651 });
652 btnSearchStudent.setBounds(40, 147, 128, 23);
653 panel_4.add(btnSearchStudent);
654
655 JLabel lblSearchStudentInfo = new JLabel("Search student");
656 lblSearchStudentInfo.setFont(new Font("Tahoma", Font.BOLD, 14));
657 lblSearchStudentInfo.setBounds(40, 31, 181, 20);
658 panel_4.add(lblSearchStudentInfo);
659
660 JLabel lblSearchCourseInfo = new JLabel("Search course");
661 lblSearchCourseInfo.setFont(new Font("Tahoma", Font.BOLD, 14));
662 lblSearchCourseInfo.setBounds(465, 31, 175, 20);
663 panel_4.add(lblSearchCourseInfo);
664
665 JLabel lblCourseCode_3 = new JLabel("Course code:");
666 lblCourseCode_3.setBounds(465, 67, 92, 14);
667 panel_4.add(lblCourseCode_3);
668
669 JLabel lblCourseName_1 = new JLabel("Course name:");
670 lblCourseName_1.setBounds(465, 95, 105, 14);
671 panel_4.add(lblCourseName_1);
672
673 JLabel lblCoursePoints_1 = new JLabel("Course points:");
674 lblCoursePoints_1.setBounds(465, 123, 92, 14);
675 panel_4.add(lblCoursePoints_1);
676
677 textFieldSearchCcode = new JTextField();
678 textFieldSearchCcode.setBounds(573, 64, 175, 20);
679 panel_4.add(textFieldSearchCcode);
680 textFieldSearchCcode.setColumns(10);
681
682 textFieldSearchCname = new JTextField();
683 textFieldSearchCname.setEditable(false);
684 textFieldSearchCname.setBounds(573, 92, 175, 20);
685 panel_4.add(textFieldSearchCname);
686 textFieldSearchCname.setColumns(10);
687
688 textFieldSearchCpoints = new JTextField();
689 textFieldSearchCpoints.setEditable(false);
690 textFieldSearchCpoints.setBounds(573, 120, 175, 20);
691 panel_4.add(textFieldSearchCpoints);
692 textFieldSearchCpoints.setColumns(10);
693
694 JLabel lblInfoSearch_2 = new JLabel("Message:");
695 lblInfoSearch_2.setFont(new Font("Tahoma", Font.PLAIN, 9));
696 lblInfoSearch_2.setBounds(465, 181, 351, 14);
697 panel_4.add(lblInfoSearch_2);
698
699 JButton btnSearchCourse = new JButton("Search");
700 btnSearchCourse.addActionListener(new ActionListener() {
701 public void actionPerformed(ActionEvent e) {
702 String cCode = textFieldSearchCcode.getText();
703
704 try {
705 if (textFieldSearchCcode.getText().equals("")) {
706 lblInfoSearch_2.setText("Message: No course code entered.");
707 } else {
708 textFieldSearchCname.setText(controller.findCourse(cCode).getCname());
709 String cPoints = Integer.toString(controller.findCourse(cCode).getCcp());
710 textFieldSearchCpoints.setText(cPoints);
711 lblInfoSearch_2.setText("Message: Showing course information.");
712 }
713 } catch (Exception e1) {
714 lblInfoSearch_2.setText("Message: Could not find course.");
715 }
716
717 }
718 });
719 btnSearchCourse.setBounds(465, 147, 128, 23);
720 panel_4.add(btnSearchCourse);
721
722 JLabel lblShowStudentResult = new JLabel("Search overall results for courses");
723 lblShowStudentResult.setFont(new Font("Tahoma", Font.BOLD, 14));
724 lblShowStudentResult.setBounds(464, 285, 340, 20);
725 panel_4.add(lblShowStudentResult);
726
727 JLabel lblNewLabel_4 = new JLabel("Course code:");
728 lblNewLabel_4.setBounds(464, 327, 93, 14);
729 panel_4.add(lblNewLabel_4);
730
731 JLabel lblNewLabel_5 = new JLabel("Semester:");
732 lblNewLabel_5.setBounds(465, 354, 64, 14);
733 panel_4.add(lblNewLabel_5);
734
735 textFieldSearchListCcode = new JTextField();
736 textFieldSearchListCcode.setBounds(573, 324, 86, 20);
737 panel_4.add(textFieldSearchListCcode);
738 textFieldSearchListCcode.setColumns(10);
739
740 JComboBox<String> comboBoxSearchList = new JComboBox<String>();
741 comboBoxSearchList.addItem("HT13");
742 comboBoxSearchList.addItem("VT14");
743 comboBoxSearchList.addItem("HT14");
744 comboBoxSearchList.addItem("VT15");
745 comboBoxSearchList.addItem("HT15");
746 comboBoxSearchList.setBounds(573, 351, 86, 20);
747 panel_4.add(comboBoxSearchList);
748
749 JLabel lblMessageInteractCcode = new JLabel("Message:");
750 lblMessageInteractCcode.setFont(new Font("Tahoma", Font.PLAIN, 9));
751 lblMessageInteractCcode.setBounds(464, 379, 352, 14);
752 panel_4.add(lblMessageInteractCcode);
753
754
755 dataModel = new DefaultTableModel();
756 table = new JTable(dataModel);
757 scrollPane = new JScrollPane(table);
758 scrollPane.setBounds(465, 419, 351, 156);
759 panel_4.add(scrollPane);
760
761 String[] headers = { "Student ID", "Name", "Grade" };
762 dataModel.setColumnIdentifiers(headers);
763
764 JButton btnSearchList = new JButton("Search");
765 btnSearchList.addActionListener(new ActionListener() {
766 public void actionPerformed(ActionEvent e) {
767 dataModel.setRowCount(0);
768 String cCode = textFieldSearchListCcode.getText();
769 String semester = comboBoxSearchList.getSelectedItem().toString();
770
771 try {
772
773 System.out.println("rˆv");
774
775 ArrayList<Studied> gradeList = controller.getGradeList(cCode, semester);
776 System.out.println(gradeList.size());
777
778 for (Studied s : gradeList) {
779 System.out.println("12s" + s.getSname());
780 String[] col = new String[3];
781
782 col[0] = s.getSsid();
783 col[1] = s.getSname();
784 col[2] = s.getGrade();
785 dataModel.addRow(col);
786
787
788
789
790
791
792 lblMessageInteractCcode.setText("Message: Showing result.");
793 }
794 } catch (SQLException e1) {
795 lblMessageInteractCcode.setText("Message: Could not find course code.");
796 }
797 }
798 });
799 btnSearchList.setBounds(727, 350, 89, 23);
800 panel_4.add(btnSearchList);
801
802
803
804
805
806
807
808
809 textFieldSearchGradeSsid = new JTextField();
810 textFieldSearchGradeSsid.setBounds(151, 331, 86, 20);
811 panel_4.add(textFieldSearchGradeSsid);
812 textFieldSearchGradeSsid.setColumns(10);
813
814 textFieldSearchGradeCcode = new JTextField();
815 textFieldSearchGradeCcode.setBounds(151, 356, 86, 20);
816 panel_4.add(textFieldSearchGradeCcode);
817 textFieldSearchGradeCcode.setColumns(10);
818
819
820
821 // Sˆker
822
823
824
825 JLabel lblSearchGradeFor = new JLabel("Search student's grade");
826 lblSearchGradeFor.setFont(new Font("Tahoma", Font.BOLD, 14));
827 lblSearchGradeFor.setBounds(43, 285, 181, 20);
828 panel_4.add(lblSearchGradeFor);
829
830 JLabel lblStudentId_2 = new JLabel("Student ID:");
831 lblStudentId_2.setBounds(43, 334, 92, 14);
832 panel_4.add(lblStudentId_2);
833
834 JLabel lblCourseCode_4 = new JLabel("Course code:");
835 lblCourseCode_4.setBounds(43, 359, 92, 14);
836 panel_4.add(lblCourseCode_4);
837
838 JLabel lblMessageInteractionSearchGrade = new JLabel("Message:");
839 lblMessageInteractionSearchGrade.setFont(new Font("Tahoma", Font.PLAIN, 9));
840 lblMessageInteractionSearchGrade.setBounds(43, 381, 351, 14);
841 panel_4.add(lblMessageInteractionSearchGrade);
842
843 dataModel_3 = new DefaultTableModel();
844 table_3 = new JTable(dataModel_3);
845 scrollPane_3 = new JScrollPane(table_3);
846
847 scrollPane_3.setBounds(55, 419, 357, 156);
848 panel_4.add(scrollPane_3);
849
850 String[] headersSearch = { "Student ID", "Course code", "Grade", "Semester" };
851 dataModel_3.setColumnIdentifiers(headersSearch);
852
853 JButton btnSearch = new JButton("Search");
854 btnSearch.addActionListener(new ActionListener() {
855 public void actionPerformed(ActionEvent e) {
856 String sSid = textFieldSearchGradeSsid.getText();
857 String cCode = textFieldSearchGradeCcode.getText();
858
859 try {
860 if (textFieldSearchGradeSsid.getText().equals("")
861 || textFieldSearchGradeCcode.getText().equals("")) {
862 lblMessageInteractionSearchGrade.setText("Message: No student ID or Course code entered.");
863 } else {
864 dataModel_3.setRowCount(0);
865 ArrayList<Studied> courseList = controller.findGrade(sSid, cCode);
866
867 for (Studied c : courseList) {
868 String[] col = new String[4];
869 col[0] = c.getSsid();
870 col[1] = c.getSname();
871 col[2] = c.getGrade();
872 col[3] = c.getSemester();
873 dataModel_3.addRow(col);
874 }
875 lblMessageInteractionSearchGrade.setText("Message: Showing result.");
876 }
877 } catch (SQLException e1) {
878 lblMessageInteractionSearchGrade.setText("Message: Could not find grade.");
879
880 }
881
882 }
883 });
884 btnSearch.setBounds(305, 353, 89, 23);
885 panel_4.add(btnSearch);
886
887 JButton btnClear = new JButton("Clear");
888 btnClear.addActionListener(new ActionListener() {
889 public void actionPerformed(ActionEvent e) {
890 textFieldSearchSsid.setText(null);
891 textFieldSearchSname.setText(null);
892 textFieldSearchAddress.setText(null);
893 lblInfoSearch_1.setText("Message:");
894 }
895 });
896 btnClear.setBounds(195, 147, 128, 23);
897 panel_4.add(btnClear);
898
899 JButton btnClear_1 = new JButton("Clear");
900 btnClear_1.addActionListener(new ActionListener() {
901 public void actionPerformed(ActionEvent e) {
902 textFieldSearchCcode.setText(null);
903 textFieldSearchCname.setText(null);
904 textFieldSearchCpoints.setText(null);
905 lblInfoSearch_2.setText("Message:");
906 }
907 });
908 btnClear_1.setBounds(620, 147, 128, 23);
909 panel_4.add(btnClear_1);
910
911 JButton btnClear_2 = new JButton("Clear");
912 btnClear_2.addActionListener(new ActionListener() {
913 public void actionPerformed(ActionEvent e) {
914 textFieldSearchGradeSsid.setText(null);
915 textFieldSearchGradeCcode.setText(null);
916 dataModel_3.setRowCount(0);
917 lblMessageInteractionSearchGrade.setText("Message:");
918 }
919 });
920 btnClear_2.setBounds(329, 325, 65, 23);
921 panel_4.add(btnClear_2);
922
923 JSeparator separator_1 = new JSeparator();
924 separator_1.setBounds(40, 247, 776, 2);
925 panel_4.add(separator_1);
926
927 JButton btnClear_3 = new JButton("Clear");
928 btnClear_3.addActionListener(new ActionListener() {
929 public void actionPerformed(ActionEvent e) {
930 textFieldSearchListCcode.setText(null);
931 dataModel.setRowCount(0);
932 lblMessageInteractCcode.setText("Message:");
933
934 }
935 });
936 btnClear_3.setBounds(751, 323, 65, 23);
937 panel_4.add(btnClear_3);
938
939 JPanel panel_1 = new JPanel();
940 tabbedPane.addTab("Search2", null, panel_1, null);
941 panel_1.setLayout(null);
942
943 dataModel_4 = new DefaultTableModel();
944
945 String[] headersAdvSearch = { "Student ID", "Student name", "Address" };
946 dataModel_4.setColumnIdentifiers(headersAdvSearch);
947
948 JLabel lblGetProcentageOf = new JLabel("Procentage with grade 'A'");
949 lblGetProcentageOf.setFont(new Font("Tahoma", Font.BOLD, 14));
950 lblGetProcentageOf.setBounds(49, 25, 317, 20);
951 panel_1.add(lblGetProcentageOf);
952
953 JLabel lblCourseCode_6 = new JLabel("Course code:");
954 lblCourseCode_6.setBounds(49, 69, 97, 14);
955 panel_1.add(lblCourseCode_6);
956
957 textFieldAdvCcode_1 = new JTextField();
958 textFieldAdvCcode_1.setBounds(158, 66, 86, 20);
959 panel_1.add(textFieldAdvCcode_1);
960 textFieldAdvCcode_1.setColumns(10);
961
962 JLabel lblProcentage = new JLabel("Procentage: (%)");
963 lblProcentage.setBounds(48, 152, 98, 14);
964 panel_1.add(lblProcentage);
965
966 textFieldAdvProcent = new JTextField();
967 textFieldAdvProcent.setEditable(false);
968 textFieldAdvProcent.setBounds(158, 150, 86, 20);
969 panel_1.add(textFieldAdvProcent);
970 textFieldAdvProcent.setColumns(10);
971
972 JComboBox<String> comboBoxAdvSemester_1 = new JComboBox<String>();
973 comboBoxAdvSemester_1.addItem("HT13");
974 comboBoxAdvSemester_1.addItem("VT14");
975 comboBoxAdvSemester_1.addItem("HT14");
976 comboBoxAdvSemester_1.addItem("VT15");
977 comboBoxAdvSemester_1.addItem("HT15");
978 comboBoxAdvSemester_1.setBounds(158, 94, 86, 20);
979 panel_1.add(comboBoxAdvSemester_1);
980
981 JLabel lblNewLabelInteractionProcentage = new JLabel("Message:");
982 lblNewLabelInteractionProcentage.setFont(new Font("Tahoma", Font.PLAIN, 9));
983 lblNewLabelInteractionProcentage.setBounds(47, 126, 296, 14);
984 panel_1.add(lblNewLabelInteractionProcentage);
985
986 JButton btnSearch_1 = new JButton("Search");
987 btnSearch_1.addActionListener(new ActionListener() {
988 public void actionPerformed(ActionEvent e) {
989 String cCode = textFieldAdvCcode_1.getText();
990 String semester = comboBoxAdvSemester_1.getSelectedItem().toString();
991
992 try {
993 if (textFieldAdvCcode_1.getText().equals("")) {
994 lblNewLabelInteractionProcentage.setText("Message: No course code enterd.");
995 } else {
996 textFieldAdvProcent.setText(controller.getPercentageGradeA(cCode, semester));
997 lblNewLabelInteractionProcentage.setText("Message: Showing result");
998 }
999 } catch (SQLException e1) {
1000 lblNewLabelInteractionProcentage.setText("Message: Could not find the procentage.");
1001 }
1002 }
1003 });
1004 btnSearch_1.setBounds(254, 93, 89, 23);
1005 panel_1.add(btnSearch_1);
1006
1007 JLabel lblGetCourseWith = new JLabel("Find course with highest passing rate");
1008 lblGetCourseWith.setFont(new Font("Tahoma", Font.BOLD, 14));
1009 lblGetCourseWith.setBounds(472, 25, 317, 20);
1010 panel_1.add(lblGetCourseWith);
1011
1012 textFieldStudentFlow = new JTextField();
1013 textFieldStudentFlow.setEditable(false);
1014 textFieldStudentFlow.setBounds(581, 72, 86, 20);
1015 panel_1.add(textFieldStudentFlow);
1016 textFieldStudentFlow.setColumns(10);
1017
1018 JLabel lblCourseCode_7 = new JLabel("Course code:");
1019 lblCourseCode_7.setBounds(472, 75, 97, 14);
1020 panel_1.add(lblCourseCode_7);
1021
1022 JLabel lblNewLabelInteractionBestFlow = new JLabel("Message:");
1023 lblNewLabelInteractionBestFlow.setFont(new Font("Tahoma", Font.PLAIN, 9));
1024 lblNewLabelInteractionBestFlow.setBounds(472, 100, 294, 14);
1025 panel_1.add(lblNewLabelInteractionBestFlow);
1026
1027 JButton btnSearchStudentsFlow = new JButton("Search");
1028 btnSearchStudentsFlow.addActionListener(new ActionListener() {
1029 public void actionPerformed(ActionEvent e) {
1030 try {
1031 textFieldStudentFlow.setText(controller.getStudentFlow().toString());
1032 lblNewLabelInteractionBestFlow.setText("Showing result.");
1033 } catch (SQLException e1) {
1034 lblNewLabelInteractionBestFlow.setText("Could not find best student flow.");
1035 }
1036 }
1037 });
1038 btnSearchStudentsFlow.setBounds(677, 71, 89, 23);
1039 panel_1.add(btnSearchStudentsFlow);
1040
1041 JSeparator separator_2 = new JSeparator();
1042 separator_2.setBounds(25, 193, 792, 2);
1043 panel_1.add(separator_2);
1044
1045 }
1046}