Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.66 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package pluto.gui;
  7.  
  8. import java.awt.BorderLayout;
  9. import java.awt.Color;
  10. import java.awt.Dimension;
  11. import java.awt.Font;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18. import javax.swing.DefaultComboBoxModel;
  19. import javax.swing.DefaultListModel;
  20. import javax.swing.ImageIcon;
  21. import javax.swing.JButton;
  22. import javax.swing.JCheckBox;
  23. import javax.swing.JComboBox;
  24. import static javax.swing.JFrame.EXIT_ON_CLOSE;
  25. import javax.swing.JFrame;
  26. import javax.swing.JLabel;
  27. import javax.swing.JList;
  28. import javax.swing.JOptionPane;
  29. import javax.swing.JPanel;
  30. import javax.swing.JPasswordField;
  31. import javax.swing.JScrollPane;
  32. import javax.swing.JTabbedPane;
  33. import javax.swing.JTable;
  34. import javax.swing.JTextField;
  35. import javax.swing.SpringLayout;
  36. import javax.swing.table.AbstractTableModel;
  37. import pluto.gui.tableModel.SubjectTableModel;
  38. import pluto.gui.tableModel.UserTableModel;
  39. import pluto.logic.DataSource;
  40. import pluto.logic.entities.PlutoUser;
  41. import pluto.logic.entities.Subject;
  42.  
  43. /**
  44. *
  45. * @author Varga Bence
  46. */
  47. public class PlutoFrame extends JFrame {
  48.  
  49. private String currentusername;
  50.  
  51. // MAIN SCREEN KOMPONENSEK (PLUTO)
  52. JTextField username = new JTextField(10);
  53. JPasswordField password = new JPasswordField(10);
  54. JPanel panel = new JPanel();
  55. JFrame pluto = new JFrame();
  56. JLabel mainlabel = new JLabel("Belépés");
  57. JLabel userlabel = new JLabel("Felhasználó név:");
  58. JLabel passwlabel = new JLabel("Jelszó:");
  59. //ImageIcon plutojpg = new ImageIcon(getClass().getResource("pluto.jpg"));
  60. //JLabel plutopic = new JLabel(plutojpg);
  61. JCheckBox isteacher = new JCheckBox("Tanár");
  62. JButton login = new JButton("Belépés");
  63. JButton registration = new JButton("Regisztráció");
  64. ImageIcon realpluto = new ImageIcon(getClass().getResource("plutoreal.jpg"));
  65. JLabel realplutopic = new JLabel(realpluto);
  66.  
  67. //REGISZTRÁCIÓS KOMPONENSEK
  68. JFrame regframe = new JFrame();
  69. JPanel regpanel = new JPanel();
  70. JLabel reglabel = new JLabel("Regisztráció");
  71. JLabel regnamelabel = new JLabel("Neve:");
  72. JLabel regusernamelabel = new JLabel("Felhasználóneve:");
  73. JLabel regpasswordlabel = new JLabel("Jelszó:");
  74. JLabel studentlabel = new JLabel("(Alapértelmezett: diák.)");
  75. JCheckBox registeacher = new JCheckBox("Tanár");
  76. JTextField regusername = new JTextField(20);
  77. JPasswordField regpassword = new JPasswordField(10);
  78. JTextField regname = new JTextField(20);
  79.  
  80. JButton regbutton = new JButton("Regisztrálok");
  81. JButton backbutton = new JButton("Vissza");
  82.  
  83. private UserTableModel userModel;
  84. private SubjectTableModel subModel;
  85. private JTable usertable;
  86.  
  87. //DIÁK FRAME KOMPONENSEI
  88. JFrame studentframe = new JFrame();
  89. JPanel studentpanel;
  90. JButton addsub = new JButton("Tárgy felvétele");
  91. JButton scedule = new JButton("Órarend");
  92. JButton removesub = new JButton("Tárgy leadása");
  93. JButton studentexit = new JButton("Kilépés");
  94. JPanel sudentpanel = new JPanel();
  95.  
  96. ImageIcon studentjpg = new ImageIcon(getClass().getResource("student.jpg"));
  97. JLabel studentpic = new JLabel(studentjpg);
  98.  
  99. //TANÁR FRAME KOMPONENSEI
  100. JFrame teacherframe = new JFrame();
  101. JButton addsubjectbutton = new JButton("Tárgy hozzáadása");
  102. JButton activstudentsbutton = new JButton("Hallgatók listája");
  103. JButton exitbutton = new JButton("Kilépés");
  104. JPanel teacherpanel = new JPanel();
  105.  
  106. ImageIcon img2 = new ImageIcon(getClass().getResource("teacherdesk.jpg"));
  107. JLabel teacherpic = new JLabel(img2);
  108. JButton removesubject = new JButton("Tárgy Törlés");
  109.  
  110. // TÁRGY HOZZÁADÁSA KOMPONENSEI
  111. JTextField addsubname = new JTextField(30);
  112. JTextField addsubroom = new JTextField(20);
  113. JTextField addsubtime = new JTextField(20);
  114. JTextField addsubregsem = new JTextField(5);
  115. JLabel addsubnamelabel = new JLabel("Tárgy neve");
  116. JLabel addsubroomlabel = new JLabel("Helyszín");
  117. JLabel addsubtimelabel = new JLabel("Időpont");
  118. JLabel addsubregsemlabel = new JLabel("Ajánlott félév");
  119. JLabel addsubreqlabel = new JLabel("Előfeltétele");
  120. JLabel teacherlabel = new JLabel("Oktató");
  121. JButton addsubject = new JButton("Hozzáad");
  122. JButton addsubjectcancel = new JButton("Vissza");
  123. String[] semester = {"1.félév", "2.félév", "3.félév", "4.félév", "5.félév", "6.félév"};
  124. String[] day = {"Hétfő", "Kedd", "Szerda", "Csütörtök", "Péntek"};
  125. String[] hour = {"8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00"};
  126. JCheckBox reqbox;
  127. JComboBox<String> comboDay;
  128. JComboBox<String> comboHour;
  129. ImageIcon board2 = new ImageIcon(getClass().getResource("teacherdesk.jpg"));
  130. JLabel classboard2 = new JLabel(board2);
  131. JComboBox<String> comboSemester;
  132. String[] comboTeacherarray;
  133. JComboBox<String> comboTeacher;
  134. JPanel addpanel = new JPanel();
  135. JFrame addsubframe;
  136.  
  137. Subject reqsub = new Subject();
  138.  
  139. // tárgyak adatai -- TÖRLÉSNÉL
  140. JLabel subdetname = new JLabel("Tantárgy neve:");
  141. JLabel currentsubname;
  142. JLabel subdetroom = new JLabel("Terem:");
  143. JLabel currentsubroom;
  144. JLabel subdettime = new JLabel("Időpont:");
  145. JLabel currentsubtime;
  146. JLabel subdetteacher = new JLabel("Tanár neve:");
  147. JLabel currentsubteacher;
  148. JButton delete = new JButton("Tárgy törlése");
  149. // JButton cancel = new JButton("Mégse");
  150. JLabel subdetmain = new JLabel("Válasszon tantárgyat:");
  151. String[] currentids;
  152. JComboBox<String> comboId;
  153. JFrame subdetailsframe;
  154. JPanel subdet = new JPanel();
  155. ImageIcon board = new ImageIcon(getClass().getResource("teacherdesk.jpg"));
  156. JLabel classboard = new JLabel(board);
  157.  
  158. JLabel reqsublabel = new JLabel("Előfeltétel:");
  159. String[] comboRequiredarray;
  160. JComboBox<String> comboReqsub;
  161.  
  162. JFrame mysubframe;
  163. JPanel mysubp;
  164.  
  165. JButton mysubject = new JButton("Felvett tárgyak");
  166. JPanel subdet2 = new JPanel();
  167.  
  168. JButton myfulfilledbutton = new JButton("Teljesített tárgyaim");
  169. JFrame myfullsubframe;
  170. JPanel myfullsubp;
  171.  
  172. JComboBox<String> comboId2;
  173.  
  174. JList list;
  175. PlutoUser doneuser;
  176.  
  177. JLabel currentsubname2;
  178. JLabel currentsubroom2;
  179. JLabel currentsubtime2;
  180. JLabel currentsubteacher2;
  181.  
  182. JButton addsubtomylist;
  183.  
  184. public PlutoFrame() {
  185. gui();
  186. }
  187.  
  188. public void studentGui() {
  189. pluto.setVisible(false);
  190. studentframe.setVisible(true);
  191. studentframe.setTitle("Plutó hallgatói tanulmányirendszer - DIÁK");
  192. studentframe.setDefaultCloseOperation(EXIT_ON_CLOSE);
  193. studentframe.setSize(510, 300);
  194. studentframe.setResizable(false);
  195. studentframe.setLocationRelativeTo(null);
  196. studentpanel = new JPanel();
  197.  
  198. SpringLayout l3 = new SpringLayout();
  199. studentpanel.setLayout(l3);
  200.  
  201. JTabbedPane stpane = new JTabbedPane();
  202. stpane.addTab("Diák", studentpanel);
  203. stpane.addTab("Tárgyfelvétel", subdet2);
  204.  
  205. studentframe.add(stpane);
  206. studentpanel.add(scedule);
  207. studentpanel.add(studentexit);
  208. studentpanel.add(removesub);
  209. studentpanel.add(mysubject);
  210. studentpanel.add(myfulfilledbutton);
  211. studentpanel.add(studentpic);
  212.  
  213. l3.putConstraint(SpringLayout.NORTH, studentpic, 0, SpringLayout.NORTH, studentpanel);
  214. l3.putConstraint(SpringLayout.NORTH, scedule, 95, SpringLayout.NORTH, studentpanel);
  215. l3.putConstraint(SpringLayout.WEST, scedule, 5, SpringLayout.WEST, studentpanel);
  216. l3.putConstraint(SpringLayout.NORTH, studentexit, 5, SpringLayout.NORTH, studentpanel);
  217. l3.putConstraint(SpringLayout.WEST, studentexit, 420, SpringLayout.WEST, studentpanel);
  218. l3.putConstraint(SpringLayout.NORTH, removesub, 35, SpringLayout.NORTH, studentpanel);
  219. l3.putConstraint(SpringLayout.WEST, removesub, 5, SpringLayout.WEST, studentpanel);
  220. l3.putConstraint(SpringLayout.WEST, mysubject, 5, SpringLayout.WEST, studentpanel);
  221. l3.putConstraint(SpringLayout.NORTH, mysubject, 5, SpringLayout.NORTH, studentpanel);
  222. l3.putConstraint(SpringLayout.WEST, myfulfilledbutton, 5, SpringLayout.WEST, studentpanel);
  223. l3.putConstraint(SpringLayout.NORTH, myfulfilledbutton, 65, SpringLayout.NORTH, studentpanel);
  224.  
  225. studentexit.addActionListener(new ActionListener() {
  226.  
  227. @Override
  228. public void actionPerformed(ActionEvent e) {
  229.  
  230. for (int i = 0; i < userModel.getRowCount(); i++) {
  231. PlutoUser compareuser = DataSource.getInstance().getUserController().findPlutoUserEntities().get(i);
  232. if (currentusername.equals(compareuser.getUsername())) {
  233. userModel.turnOffline(compareuser);
  234. userModel.fireTableDataChanged();
  235. }
  236.  
  237. }
  238. studentframe.dispose();
  239. new PlutoFrame();
  240. }
  241. });
  242.  
  243. // ********************************************* TÁRGY FELVÉTEL ************************************************
  244. SpringLayout s1 = new SpringLayout();
  245. String[] currentids2 = subModel.currentSubjectsId();
  246. comboId2 = new JComboBox<>(currentids2);
  247. currentsubname2 = new JLabel("");
  248. currentsubroom2 = new JLabel("");
  249. currentsubtime2 = new JLabel("");
  250. currentsubteacher2 = new JLabel("");
  251. currentsubname2.setForeground(Color.white);
  252. currentsubroom2.setForeground(Color.white);
  253. currentsubteacher2.setForeground(Color.white);
  254. currentsubtime2.setForeground(Color.white);
  255. subdetname.setForeground(Color.white);
  256. subdetroom.setForeground(Color.white);
  257. subdettime.setForeground(Color.white);
  258. subdetteacher.setForeground(Color.white);
  259. subdetmain.setForeground(Color.white);
  260. addsubtomylist = new JButton("Felvesz");
  261.  
  262. subdet2.setLayout(s1);
  263. subdet2.add(subdetname);
  264. subdet2.add(subdetroom);
  265. subdet2.add(subdettime);
  266. subdet2.add(comboId2);
  267. subdet2.add(subdetmain);
  268. subdet2.add(subdetteacher);
  269. subdet2.add(currentsubname2);
  270. subdet2.add(currentsubroom2);
  271. subdet2.add(currentsubtime2);
  272. subdet2.add(currentsubteacher2);
  273. subdet2.add(addsubtomylist);
  274. subdet2.add(classboard);
  275.  
  276. s1.putConstraint(SpringLayout.NORTH, classboard, 0, SpringLayout.NORTH, subdet2);
  277. s1.putConstraint(SpringLayout.WEST, subdetmain, 250, SpringLayout.WEST, subdet2);
  278. s1.putConstraint(SpringLayout.NORTH, subdetmain, 20, SpringLayout.NORTH, subdet2);
  279. s1.putConstraint(SpringLayout.WEST, subdetname, 30, SpringLayout.WEST, subdet2);
  280. s1.putConstraint(SpringLayout.NORTH, subdetname, 55, SpringLayout.NORTH, subdet2);
  281. s1.putConstraint(SpringLayout.WEST, subdetroom, 30, SpringLayout.WEST, subdet2);
  282. s1.putConstraint(SpringLayout.NORTH, subdetroom, 75, SpringLayout.NORTH, subdet2);
  283. s1.putConstraint(SpringLayout.WEST, subdettime, 30, SpringLayout.WEST, subdet2);
  284. s1.putConstraint(SpringLayout.NORTH, subdettime, 115, SpringLayout.NORTH, subdet2);
  285. s1.putConstraint(SpringLayout.WEST, comboId2, 380, SpringLayout.WEST, subdet2);
  286. s1.putConstraint(SpringLayout.NORTH, comboId2, 20, SpringLayout.NORTH, subdet2);
  287. s1.putConstraint(SpringLayout.WEST, subdetteacher, 30, SpringLayout.WEST, subdet2);
  288. s1.putConstraint(SpringLayout.NORTH, subdetteacher, 95, SpringLayout.NORTH, subdet2);
  289. s1.putConstraint(SpringLayout.WEST, currentsubname2, 125, SpringLayout.WEST, subdet2);
  290. s1.putConstraint(SpringLayout.NORTH, currentsubname2, 55, SpringLayout.NORTH, subdet2);
  291. s1.putConstraint(SpringLayout.WEST, currentsubroom2, 125, SpringLayout.WEST, subdet2);
  292. s1.putConstraint(SpringLayout.NORTH, currentsubroom2, 75, SpringLayout.NORTH, subdet2);
  293. s1.putConstraint(SpringLayout.WEST, currentsubtime2, 125, SpringLayout.WEST, subdet2);
  294. s1.putConstraint(SpringLayout.NORTH, currentsubtime2, 115, SpringLayout.NORTH, subdet2);
  295. s1.putConstraint(SpringLayout.WEST, currentsubteacher2, 125, SpringLayout.WEST, subdet2);
  296. s1.putConstraint(SpringLayout.NORTH, currentsubteacher2, 95, SpringLayout.NORTH, subdet2);
  297. s1.putConstraint(SpringLayout.WEST, addsubtomylist, 200, SpringLayout.WEST, subdet2);
  298. s1.putConstraint(SpringLayout.NORTH, addsubtomylist, 160, SpringLayout.NORTH, subdet2);
  299.  
  300. comboId2.addActionListener(new ActionListener() {
  301.  
  302. @Override
  303. public void actionPerformed(ActionEvent e) {
  304. if (e.getSource() == comboId2) {
  305. JComboBox cb = (JComboBox) e.getSource();
  306. String ids = (String) cb.getSelectedItem();
  307. String[] seged = delsubDetalis(ids);
  308. currentsubname2.setText(seged[0]);
  309. currentsubroom2.setText(seged[1]);
  310. currentsubtime2.setText(seged[2]);
  311. currentsubteacher2.setText(seged[3]);
  312.  
  313. }
  314.  
  315. }
  316. });
  317.  
  318. addsubtomylist.addActionListener(new ActionListener() {
  319.  
  320. @Override
  321. public void actionPerformed(ActionEvent e) {
  322.  
  323. if (comboId2.getItemCount() < 1) {
  324.  
  325. JOptionPane.showMessageDialog(studentframe, "Nincs több tantárgy!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  326. } else {
  327.  
  328. String ids = (String) comboId2.getSelectedItem();
  329. int realid = Integer.parseInt(ids);
  330.  
  331. for (int i = 0; i < subModel.getRowCount(); i++) {
  332. Subject sub = DataSource.getInstance().getSubjectController().findSubjectEntities().get(i);
  333.  
  334. if (sub.getId() == realid) {
  335. List<Integer> addsubids = new ArrayList<>();
  336. addsubids.add(realid);
  337.  
  338. if (userModel.youAlreadyHaveThisSubject(currentusername, addsubids)) {
  339. JOptionPane.showMessageDialog(studentframe, "Ezt a tárgyat már felvetted!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  340. comboId2.removeItem(comboId2.getSelectedItem());
  341. } else {
  342.  
  343. Subject selectedsub = subModel.getmySubject(realid);
  344. if (userModel.requirementCheck(selectedsub, currentusername)) {
  345. userModel.addSubjectToMyList(currentusername, subModel.getmySubject(realid));
  346. subModel.fireTableDataChanged();
  347. userModel.fireTableDataChanged();
  348. comboId2.removeItem(comboId2.getSelectedItem());
  349. JOptionPane.showMessageDialog(studentframe, "Sikeres tárgyfelvétel");
  350.  
  351. } else {
  352. JOptionPane.showMessageDialog(studentframe, "Nem teljesült a tárgy előfeltétele!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  353. }
  354.  
  355. }
  356. }
  357.  
  358. }
  359.  
  360. }
  361.  
  362. }
  363.  
  364. });
  365.  
  366. //************************************************************** TÁRGY FELVÉTEL VÉGE ****************************************************************
  367. //*************************************************************** FELVETT TÁRGYAIM ********************************************************
  368. mysubject.addActionListener(new ActionListener() {
  369.  
  370. @Override
  371. public void actionPerformed(ActionEvent e) {
  372. PlutoUser user = userModel.getThisUser(currentusername);
  373. if (user.getSubjects().isEmpty()) {
  374. JOptionPane.showMessageDialog(studentframe, "Nincs fevett tárgyad!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  375. } else {
  376. mysubframe = new JFrame();
  377. mysubframe.setVisible(true);
  378. mysubframe.setTitle("Felvett tantárgyak");
  379. mysubframe.setSize(1300, 300);
  380. mysubp = new JPanel(new BorderLayout());
  381.  
  382. JTable mysubtable = new JTable(new AbstractTableModel() {
  383. PlutoUser thisuser = userModel.getThisUser(currentusername);
  384.  
  385. @Override
  386. public int getRowCount() {
  387. return thisuser.getSubjects().size();
  388. }
  389.  
  390. @Override
  391. public int getColumnCount() {
  392. return subModel.getColumnCount();
  393. }
  394.  
  395. @Override
  396. public Object getValueAt(int rowIndex, int columnIndex) {
  397. Subject subjects = thisuser.getSubjects().get(rowIndex);
  398. switch (columnIndex) {
  399. case 0:
  400. return subjects.getSubjectName();
  401. case 1:
  402. return subjects.getRoom();
  403. case 2:
  404. return subjects.getSubDay();
  405. case 3:
  406. return subjects.getSubHour();
  407. case 4:
  408. return subjects.getRegistered_sem();
  409. case 5:
  410. return subjects.getRequirement();
  411. case 6:
  412. return subjects.getTeacherName();
  413. default:
  414. return null;
  415. }
  416. }
  417.  
  418. @Override
  419. public Class<?> getColumnClass(int columnIndex) {
  420. switch (columnIndex) {
  421. case 0:
  422. return String.class;
  423. case 1:
  424. return String.class;
  425. case 2:
  426. return String.class;
  427. case 3:
  428. return String.class;
  429. case 4:
  430. return Integer.class;
  431. case 5:
  432. return Subject.class;
  433. default:
  434. return String.class;
  435. }
  436. }
  437.  
  438. @Override
  439. public String getColumnName(int column) {
  440. return subModel.getColumnName(column);
  441. }
  442. });
  443. mysubframe.add(mysubp);
  444. mysubp.add(add(new JScrollPane(mysubtable)), BorderLayout.CENTER);
  445. }
  446.  
  447. }
  448. });
  449.  
  450. //*************************************************************** FELVETT TÁRGYAIM ********************************************************
  451. removesub.addActionListener(new ActionListener() {
  452.  
  453. @Override
  454. public void actionPerformed(ActionEvent e) {
  455. PlutoUser student = userModel.getThisUser(currentusername);
  456. Object[] mysubjects = userModel.getMySubjectArray(student.getSubjects());
  457.  
  458. if (student.getSubjects().isEmpty()) {
  459. JOptionPane.showMessageDialog(studentframe, "Nincs felvett tárgyad!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  460. } else {
  461. String selectedsub = (String) JOptionPane.showInputDialog(
  462. mysubframe,
  463. "Felvett tárgyak",
  464. "Tárgy leadása",
  465. JOptionPane.PLAIN_MESSAGE,
  466. null,
  467. mysubjects,
  468. null);
  469.  
  470. if (selectedsub != null) {
  471. List<Subject> studentsubjects = student.getSubjects();
  472. Subject thissub = userModel.getThisSubjectFromMyList(selectedsub, student);
  473. student.getSubjects().remove(thissub);
  474. student.setSubjects(studentsubjects);
  475. try {
  476. DataSource.getInstance().getUserController().edit(student);
  477. } catch (Exception ex) {
  478. Logger.getLogger(PlutoFrame.class.getName()).log(Level.SEVERE, null, ex);
  479. }
  480. userModel.fireTableDataChanged();
  481. JOptionPane.showMessageDialog(mysubframe, "Sikeres lejelentkezés!");
  482. String[] currentids2 = subModel.currentSubjectsId();
  483. comboId2.setModel(new DefaultComboBoxModel<>(currentids2));
  484.  
  485. }
  486. }
  487.  
  488. }
  489.  
  490. });
  491.  
  492. scedule.addActionListener(new ActionListener() {
  493.  
  494. @Override
  495. public void actionPerformed(ActionEvent e) {
  496. JFrame sceduleframe = new JFrame();
  497. sceduleframe.setVisible(true);
  498. sceduleframe.setTitle("Órarend");
  499. sceduleframe.setSize(1300, 220);
  500.  
  501. Object[] columnname = {"Órarend", "Hétfő", "Kedd", "Szerda", "Csütörtök", "Péntek"};
  502. Object[][] data = new Object[10][6];
  503.  
  504. PlutoUser user = userModel.getThisUser(currentusername);
  505.  
  506. for (int i = 0; i < 10; i++) {
  507. for (int j = 0; j < 6; j++) {
  508. data[i][0] = hour[i];
  509. for (int x = 0; x < user.getSubjects().size(); x++) {
  510. if (user.getSubjects().get(x).getSubHour().equals(data[i][0]) && user.getSubjects().get(x).getSubDay().equals(columnname[j])) {
  511. data[i][j] = user.getSubjects().get(x).getSubjectName();
  512.  
  513. }
  514. }
  515. }
  516. }
  517.  
  518.  
  519.  
  520. JTable orarend = new JTable(data, columnname);
  521. orarend.setPreferredScrollableViewportSize(new Dimension(450, 63));
  522. orarend.setFillsViewportHeight(true);
  523. JScrollPane scp = new JScrollPane(orarend);
  524. sceduleframe.add(scp);
  525.  
  526. }
  527.  
  528. });
  529.  
  530. myfulfilledbutton.addActionListener(new ActionListener() {
  531. @Override
  532. public void actionPerformed(ActionEvent e) {
  533. PlutoUser auser = userModel.getThisUser(currentusername);
  534. if (auser.getFulfilledsubids() == null) {
  535. JOptionPane.showMessageDialog(sudentpanel, "Nincs teljesített tantárgyad!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  536. } else {
  537. myfullsubframe = new JFrame();
  538. myfullsubframe.setVisible(true);
  539. myfullsubframe.setTitle("Teljesített tantárgyak");
  540. myfullsubframe.setSize(1300, 300);
  541. myfullsubp = new JPanel(new BorderLayout());
  542.  
  543. JTable myfullsubtable = new JTable(new AbstractTableModel() {
  544. PlutoUser thisuser = userModel.getThisUser(currentusername);
  545.  
  546. @Override
  547. public int getRowCount() {
  548. return subModel.getThisUserFulfilledSubject(thisuser).size();
  549. }
  550.  
  551. @Override
  552. public int getColumnCount() {
  553. return subModel.getColumnCount();
  554. }
  555.  
  556. @Override
  557. public Object getValueAt(int rowIndex, int columnIndex) {
  558. Subject subjects = subModel.getThisUserFulfilledSubject(thisuser).get(rowIndex);
  559. switch (columnIndex) {
  560. case 0:
  561. return subjects.getSubjectName();
  562. case 1:
  563. return subjects.getRoom();
  564. case 2:
  565. return subjects.getSubDay();
  566. case 3:
  567. return subjects.getSubHour();
  568. case 4:
  569. return subjects.getRegistered_sem();
  570. case 5:
  571. return subjects.getRequirement();
  572. case 6:
  573. return subjects.getTeacherName();
  574. default:
  575. return null;
  576. }
  577. }
  578.  
  579. @Override
  580. public Class<?> getColumnClass(int columnIndex) {
  581. switch (columnIndex) {
  582. case 0:
  583. return String.class;
  584. case 1:
  585. return String.class;
  586. case 2:
  587. return String.class;
  588. case 3:
  589. return String.class;
  590. case 4:
  591. return Integer.class;
  592. case 5:
  593. return Subject.class;
  594. default:
  595. return String.class;
  596.  
  597. }
  598. }
  599.  
  600. @Override
  601. public String getColumnName(int column) {
  602. return subModel.getColumnName(column);
  603. }
  604. });
  605. myfullsubframe.add(myfullsubp);
  606. myfullsubp.add(add(new JScrollPane(myfullsubtable)), BorderLayout.CENTER);
  607.  
  608. }
  609.  
  610. }
  611. });
  612.  
  613. }
  614.  
  615. private void gui() {
  616.  
  617. // FRAME beállítás
  618. pluto.setVisible(true);
  619. pluto.setTitle("Plutó hallgatói tanulmányirendszer");
  620. pluto.setDefaultCloseOperation(EXIT_ON_CLOSE);
  621. pluto.setSize(500, 250);
  622. pluto.setLocationRelativeTo(null);
  623. pluto.setResizable(false);
  624. SpringLayout s2 = new SpringLayout();
  625. panel.setLayout(s2);
  626.  
  627. // User megjelenítő a regisztrálok gombnál
  628. userModel = new UserTableModel();
  629. subModel = new SubjectTableModel();
  630. usertable = new JTable(userModel);
  631. JPanel userpanel = new JPanel(new BorderLayout());
  632. userpanel.add(add(new JScrollPane(usertable)), BorderLayout.CENTER);
  633. //jtabPane.addTab("Hallgatók", userpanel);
  634.  
  635. mainlabel.setFont(new Font("Cooper Black", Font.PLAIN, 18));
  636. isteacher.setOpaque(false);
  637. mainlabel.setForeground(Color.WHITE);
  638. userlabel.setForeground(Color.WHITE);
  639. passwlabel.setForeground(Color.WHITE);
  640. isteacher.setForeground(Color.WHITE);
  641. //userlabel.setFont(new Font("Cooper Black", Font.PLAIN, 12));
  642. //passwlabel.setFont(new Font("Cooper Black", Font.PLAIN, 12));
  643.  
  644. //Komponensek hozzáadása
  645. panel.add(mainlabel);
  646. panel.add(userlabel);
  647. panel.add(username);
  648. panel.add(passwlabel);
  649. panel.add(password);
  650. //panel.add(plutopic);
  651. panel.add(isteacher);
  652. panel.add(login);
  653. panel.add(registration);
  654. panel.add(realplutopic);
  655. pluto.add(panel);
  656.  
  657. // Komponenesek elhelyezkedésének beállítása
  658. s2.putConstraint(SpringLayout.EAST, realplutopic, 0, SpringLayout.EAST, panel);
  659. s2.putConstraint(SpringLayout.NORTH, realplutopic, 0, SpringLayout.NORTH, panel);
  660. s2.putConstraint(SpringLayout.HORIZONTAL_CENTER, mainlabel, 5, SpringLayout.HORIZONTAL_CENTER, panel);
  661. s2.putConstraint(SpringLayout.WEST, userlabel, 10, SpringLayout.WEST, panel);
  662. s2.putConstraint(SpringLayout.NORTH, userlabel, 36, SpringLayout.NORTH, panel);
  663. s2.putConstraint(SpringLayout.WEST, username, 10, SpringLayout.WEST, panel);
  664. s2.putConstraint(SpringLayout.NORTH, username, 54, SpringLayout.NORTH, panel);
  665. s2.putConstraint(SpringLayout.WEST, passwlabel, 10, SpringLayout.WEST, panel);
  666. s2.putConstraint(SpringLayout.NORTH, passwlabel, 78, SpringLayout.NORTH, panel);
  667. s2.putConstraint(SpringLayout.WEST, password, 10, SpringLayout.WEST, panel);
  668. s2.putConstraint(SpringLayout.NORTH, password, 95, SpringLayout.NORTH, panel);
  669. s2.putConstraint(SpringLayout.WEST, isteacher, 6, SpringLayout.WEST, panel);
  670. s2.putConstraint(SpringLayout.NORTH, isteacher, 120, SpringLayout.NORTH, panel);
  671. s2.putConstraint(SpringLayout.WEST, login, 10, SpringLayout.WEST, panel);
  672. s2.putConstraint(SpringLayout.NORTH, login, 150, SpringLayout.NORTH, panel);
  673. s2.putConstraint(SpringLayout.WEST, registration, 100, SpringLayout.WEST, panel);
  674. s2.putConstraint(SpringLayout.NORTH, registration, 150, SpringLayout.NORTH, panel);
  675.  
  676. // REGISZTRÁLOK GOMB ESEMÉNYEI
  677. // - ÚJ FRAMEE ABLAK AHOL TUDUNK REGISZTRÁLNI
  678. registration.addActionListener(new ActionListener() {
  679.  
  680. @Override
  681. public void actionPerformed(ActionEvent e) {
  682. pluto.setVisible(false);
  683. regframe.setVisible(true);
  684. regframe.setDefaultCloseOperation(EXIT_ON_CLOSE);
  685. regframe.setTitle("Plutó hallgatói tanulmányirendszer - Regisztráció");
  686. regframe.setSize(600, 400);
  687. regframe.setLocationRelativeTo(null);
  688. regframe.setResizable(false);
  689. //regpanel.setBackground(new Color(72, 161, 239));
  690. //registeacher.setBackground(new Color(72, 161, 239));
  691. reglabel.setFont(new Font("Cooper Black", Font.PLAIN, 18));
  692. SpringLayout s2 = new SpringLayout();
  693. regpanel.setLayout(s2);
  694.  
  695. reglabel.setForeground(Color.WHITE);
  696. regnamelabel.setForeground(Color.WHITE);
  697. regusernamelabel.setForeground(Color.WHITE);
  698. regpasswordlabel.setForeground(Color.WHITE);
  699. registeacher.setOpaque(false);
  700. registeacher.setForeground(Color.WHITE);
  701. studentlabel.setForeground(Color.WHITE);
  702.  
  703. regframe.add(regpanel);
  704. regpanel.add(reglabel);
  705. regpanel.add(regnamelabel);
  706. regpanel.add(regusernamelabel);
  707. regpanel.add(regpasswordlabel);
  708. regpanel.add(regname);
  709. regpanel.add(regusername);
  710. regpanel.add(regpassword);
  711. regpanel.add(registeacher);
  712. regpanel.add(studentlabel);
  713. // regpanel.add(pluto2pic);
  714. regpanel.add(regbutton);
  715. regpanel.add(backbutton);
  716. regpanel.add(realplutopic);
  717.  
  718. s2.putConstraint(SpringLayout.HORIZONTAL_CENTER, reglabel, 5, SpringLayout.HORIZONTAL_CENTER, regpanel);
  719. s2.putConstraint(SpringLayout.WEST, regnamelabel, 10, SpringLayout.WEST, regpanel);
  720. s2.putConstraint(SpringLayout.NORTH, regnamelabel, 55, SpringLayout.NORTH, regpanel);
  721. s2.putConstraint(SpringLayout.WEST, regname, 10, SpringLayout.WEST, regpanel);
  722. s2.putConstraint(SpringLayout.NORTH, regname, 75, SpringLayout.NORTH, regpanel);
  723. s2.putConstraint(SpringLayout.WEST, regusernamelabel, 10, SpringLayout.WEST, regpanel);
  724. s2.putConstraint(SpringLayout.NORTH, regusernamelabel, 100, SpringLayout.NORTH, regpanel);
  725. s2.putConstraint(SpringLayout.WEST, regusername, 10, SpringLayout.WEST, regpanel);
  726. s2.putConstraint(SpringLayout.NORTH, regusername, 120, SpringLayout.NORTH, regpanel);
  727. s2.putConstraint(SpringLayout.WEST, regpasswordlabel, 10, SpringLayout.WEST, regpanel);
  728. s2.putConstraint(SpringLayout.NORTH, regpasswordlabel, 145, SpringLayout.NORTH, regpanel);
  729. s2.putConstraint(SpringLayout.WEST, regpassword, 10, SpringLayout.WEST, panel);
  730. s2.putConstraint(SpringLayout.NORTH, regpassword, 165, SpringLayout.NORTH, regpanel);
  731. s2.putConstraint(SpringLayout.WEST, registeacher, 10, SpringLayout.WEST, regpanel);
  732. s2.putConstraint(SpringLayout.NORTH, registeacher, 190, SpringLayout.NORTH, regpanel);
  733. s2.putConstraint(SpringLayout.WEST, studentlabel, 70, SpringLayout.WEST, regpanel);
  734. s2.putConstraint(SpringLayout.NORTH, studentlabel, 194, SpringLayout.NORTH, regpanel);
  735. s2.putConstraint(SpringLayout.WEST, regbutton, 10, SpringLayout.WEST, regpanel);
  736. s2.putConstraint(SpringLayout.NORTH, regbutton, 225, SpringLayout.NORTH, regpanel);
  737. s2.putConstraint(SpringLayout.WEST, backbutton, 125, SpringLayout.WEST, regpanel);
  738. s2.putConstraint(SpringLayout.NORTH, backbutton, 225, SpringLayout.NORTH, regpanel);
  739.  
  740. // VISSZA GOMB ESEMÉNYEI
  741. backbutton.addActionListener(new ActionListener() {
  742.  
  743. @Override
  744. public void actionPerformed(ActionEvent e) {
  745. regframe.setVisible(false);
  746. new PlutoFrame();
  747. }
  748. });
  749.  
  750. // REGISZTRÁL GOMB ESEMÉNYEI
  751. regbutton.addActionListener(new ActionListener() {
  752.  
  753. @Override
  754. public void actionPerformed(ActionEvent e) {
  755. JFrame userdb = new JFrame();
  756.  
  757. userdb.setVisible(false);
  758. userdb.setDefaultCloseOperation(EXIT_ON_CLOSE);
  759. userdb.setTitle("Felhasználók");
  760. userdb.setSize(600, 400);
  761. userdb.setLocationRelativeTo(null);
  762. userdb.setResizable(false);
  763.  
  764. if (regname.getText().isEmpty() || regusername.getText().isEmpty() || getCurrentPassWord(regpassword.getPassword()).isEmpty()) {
  765. JOptionPane.showMessageDialog(regframe, "Nem töltötte ki valamelyik opciót!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  766.  
  767. } else if (alreadyExist()) {
  768. JOptionPane.showMessageDialog(regframe, "Ön már szerepel az adatbázisba", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  769. } else {
  770. PlutoUser newuser = new PlutoUser();
  771. int id = userModel.getRowCount();
  772. newuser.setId(id + 1);
  773. newuser.setName(regname.getText());
  774. newuser.setUsername(regusername.getText());
  775. char[] pw = regpassword.getPassword();
  776. newuser.setPassoword(getCurrentPassWord(pw));
  777. if (registeacher.isSelected()) {
  778. newuser.setTeacher(true);
  779. }
  780. newuser.setOnline(false);
  781.  
  782. DataSource.getInstance().getUserController().create(newuser);
  783. userModel.fireTableDataChanged();
  784. JOptionPane.showMessageDialog(regframe, "Köszönjük, hogy regisztrált, most már beléphet a rendszerbe.", "Információ", JOptionPane.INFORMATION_MESSAGE);
  785. //userdb.setVisible(true);
  786. }
  787.  
  788. //userdb.add(jtabPane);
  789. }
  790. });
  791.  
  792. }
  793. });
  794.  
  795. // ########### BELÉPÉS GOMB ESEMÉNYE ##########
  796. login.addActionListener(new ActionListener() {
  797.  
  798. @Override
  799. public void actionPerformed(ActionEvent e) {
  800. if (username.getText().isEmpty() || getCurrentPassWord(password.getPassword()).isEmpty()) {
  801. JOptionPane.showMessageDialog(regframe, "Nem töltötte ki valamelyik opciót!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  802. } else {
  803.  
  804. int dbsize = userModel.getRowCount();
  805.  
  806. for (int i = 0; i < dbsize; i++) {
  807. PlutoUser compareuser = DataSource.getInstance().getUserController().findPlutoUserEntities().get(i);
  808. if (username.getText().equals(compareuser.getUsername()) && getCurrentPassWord(password.getPassword()).equals(compareuser.getPassoword())) {
  809. if (isteacher.isSelected() && compareuser.isTeacher()) {
  810. pluto.setVisible(false);
  811. teacherGui();
  812. //pluto.dispatchEvent(new WindowEvent(pluto, WindowEvent.WINDOW_CLOSING));
  813.  
  814. } else if (isteacher.isSelected() && compareuser.isTeacher() == false) {
  815.  
  816. JOptionPane.showMessageDialog(regframe, "Ön diák, nem tanár!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  817.  
  818. } else if (isteacher.isSelected() == false && compareuser.isTeacher()) {
  819.  
  820. JOptionPane.showMessageDialog(regframe, "Ön tanár, nem diák!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  821. } else {
  822. userModel.turnOnlie(compareuser);
  823. pluto.setVisible(false);
  824. studentGui();
  825.  
  826. currentusername = username.getText();
  827. userModel.fireTableDataChanged();
  828.  
  829. }
  830.  
  831. }
  832.  
  833. }
  834. if (wrongDetails()) {
  835. JOptionPane.showMessageDialog(regframe, "Hibás adatok! Ha még nem regisztrált a regisztráció gomb segítségével megteheti.", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  836. }
  837.  
  838. }
  839. }
  840. });
  841. }
  842.  
  843. private String getCurrentPassWord(char[] pw) {
  844. String currentpw = "";
  845. for (int i = 0; i < pw.length; i++) {
  846. currentpw += pw[i];
  847.  
  848. }
  849. return currentpw;
  850. }
  851.  
  852. private boolean alreadyExist() {
  853. boolean same = false;
  854. int dbsize = userModel.getRowCount();
  855. for (int i = 0; i < dbsize; i++) {
  856. PlutoUser compareuser = DataSource.getInstance().getUserController().findPlutoUserEntities().get(i);
  857. if (regusername.getText().equals(compareuser.getName())) {
  858. same = true;
  859. }
  860. }
  861.  
  862. return same;
  863.  
  864. }
  865.  
  866. private boolean wrongDetails() {
  867. boolean wrong = false;
  868. int dbsize = userModel.getRowCount();
  869. int all = 0;
  870. for (int i = 0; i < dbsize; i++) {
  871. PlutoUser compareuser = DataSource.getInstance().getUserController().findPlutoUserEntities().get(i);
  872. if (!(username.getText().equals(compareuser.getUsername())) || (!getCurrentPassWord(password.getPassword()).equals(compareuser.getPassoword()))) {
  873. all++;
  874. }
  875.  
  876. }
  877. if (all == dbsize) {
  878. wrong = true;
  879. }
  880. return wrong;
  881. }
  882.  
  883. public void teacherGui() {
  884. teacherframe.setVisible(true);
  885. teacherframe.setTitle("Plutó hallgatói tanulmányirendszer - TANÁR");
  886. teacherframe.setDefaultCloseOperation(EXIT_ON_CLOSE);
  887. teacherframe.setSize(520, 410);
  888. teacherframe.setLocationRelativeTo(null);
  889. teacherframe.setResizable(false);
  890. teacherpanel.setBackground(Color.WHITE);
  891. SpringLayout s3 = new SpringLayout();
  892. teacherpanel.setLayout(s3);
  893. currentids = subModel.currentSubjectsId();
  894. comboId = new JComboBox<>(currentids);
  895.  
  896. JTabbedPane teachertab = new JTabbedPane();
  897. teachertab.addTab("Tanár", teacherpanel);
  898. teachertab.addTab("Tárgy hozzáadása", addpanel);
  899. teachertab.addTab("Tárgy törlése", subdet);
  900.  
  901. teacherframe.add(teachertab);
  902. teacherpanel.add(exitbutton);
  903. teacherpanel.add(activstudentsbutton);
  904. teacherpanel.add(teacherpic);
  905.  
  906. s3.putConstraint(SpringLayout.WEST, teacherpic, 0, SpringLayout.WEST, teacherpanel);
  907. s3.putConstraint(SpringLayout.WEST, exitbutton, 425, SpringLayout.WEST, teacherpanel);
  908. s3.putConstraint(SpringLayout.NORTH, exitbutton, 5, SpringLayout.NORTH, teacherpanel);
  909. s3.putConstraint(SpringLayout.WEST, activstudentsbutton, 5, SpringLayout.WEST, teacherpanel);
  910. s3.putConstraint(SpringLayout.NORTH, activstudentsbutton, 5, SpringLayout.NORTH, teacherpanel);
  911.  
  912. //*********************************** TÁRGY HOZZÁADÁSA **********************************************************
  913. comboSemester = new JComboBox<>(semester);
  914. comboHour = new JComboBox<>(hour);
  915. comboDay = new JComboBox<>(day);
  916. reqbox = new JCheckBox();
  917. reqbox.setOpaque(false);
  918. reqbox.setSelected(false);
  919.  
  920. comboTeacherarray = userModel.currentteahcer();
  921. comboTeacher = new JComboBox<>(comboTeacherarray);
  922.  
  923. comboRequiredarray = (String[]) subModel.currentSubjects();
  924. comboReqsub = new JComboBox<>(comboRequiredarray);
  925. comboReqsub.setVisible(false);
  926.  
  927. addsubname.setText("");
  928. addsubroom.setText("");
  929.  
  930. SpringLayout s4 = new SpringLayout();
  931. addpanel.setLayout(s4);
  932.  
  933. addsubnamelabel.setForeground(Color.white);
  934. addsubregsemlabel.setForeground(Color.white);
  935. addsubroomlabel.setForeground(Color.white);
  936. addsubtimelabel.setForeground(Color.white);
  937. addsubreqlabel.setForeground(Color.white);
  938. reqsublabel.setForeground(Color.white);
  939. teacherlabel.setForeground(Color.white);
  940.  
  941. addpanel.add(addsubnamelabel);
  942. addpanel.add(addsubregsemlabel);
  943. addpanel.add(addsubroomlabel);
  944. addpanel.add(addsubtimelabel);
  945. addpanel.add(addsubname);
  946. addpanel.add(comboSemester);
  947. addpanel.add(reqsublabel);
  948. addpanel.add(comboReqsub);
  949. addpanel.add(addsubroom);
  950.  
  951. addpanel.add(comboDay);
  952. addpanel.add(comboHour);
  953. addpanel.add(reqbox);
  954. addpanel.add(teacherlabel);
  955. addpanel.add(comboTeacher);
  956. addpanel.add(addsubject);
  957.  
  958. addpanel.add(classboard2);
  959.  
  960. s4.putConstraint(SpringLayout.WEST, classboard2, 0, SpringLayout.WEST, addpanel);
  961. s4.putConstraint(SpringLayout.WEST, addsubnamelabel, 30, SpringLayout.WEST, addpanel);
  962. s4.putConstraint(SpringLayout.NORTH, addsubnamelabel, 25, SpringLayout.NORTH, addpanel);
  963. s4.putConstraint(SpringLayout.WEST, addsubname, 30, SpringLayout.WEST, addpanel);
  964. s4.putConstraint(SpringLayout.NORTH, addsubname, 45, SpringLayout.NORTH, addpanel);
  965. s4.putConstraint(SpringLayout.WEST, addsubroomlabel, 30, SpringLayout.WEST, addpanel);
  966. s4.putConstraint(SpringLayout.NORTH, addsubroomlabel, 66, SpringLayout.NORTH, addpanel);
  967. s4.putConstraint(SpringLayout.WEST, addsubroom, 30, SpringLayout.WEST, addpanel);
  968. s4.putConstraint(SpringLayout.NORTH, addsubroom, 85, SpringLayout.NORTH, addpanel);
  969. s4.putConstraint(SpringLayout.WEST, addsubregsemlabel, 30, SpringLayout.WEST, addpanel);
  970. s4.putConstraint(SpringLayout.NORTH, addsubregsemlabel, 108, SpringLayout.NORTH, addpanel);
  971. s4.putConstraint(SpringLayout.WEST, comboSemester, 30, SpringLayout.WEST, addpanel);
  972. s4.putConstraint(SpringLayout.NORTH, comboSemester, 125, SpringLayout.NORTH, addpanel);
  973. s4.putConstraint(SpringLayout.WEST, addsubtimelabel, 30, SpringLayout.WEST, addpanel);
  974. s4.putConstraint(SpringLayout.NORTH, addsubtimelabel, 155, SpringLayout.NORTH, addpanel);
  975. s4.putConstraint(SpringLayout.WEST, comboDay, 30, SpringLayout.WEST, addpanel);
  976. s4.putConstraint(SpringLayout.NORTH, comboDay, 172, SpringLayout.NORTH, addpanel);
  977. s4.putConstraint(SpringLayout.WEST, comboHour, 125, SpringLayout.WEST, addpanel);
  978. s4.putConstraint(SpringLayout.NORTH, comboHour, 172, SpringLayout.NORTH, addpanel);
  979. s4.putConstraint(SpringLayout.WEST, teacherlabel, 30, SpringLayout.WEST, addpanel);
  980. s4.putConstraint(SpringLayout.NORTH, teacherlabel, 200, SpringLayout.NORTH, addpanel);
  981. s4.putConstraint(SpringLayout.WEST, reqsublabel, 30, SpringLayout.WEST, addpanel);
  982. s4.putConstraint(SpringLayout.NORTH, reqsublabel, 250, SpringLayout.NORTH, addpanel);
  983. s4.putConstraint(SpringLayout.WEST, comboTeacher, 30, SpringLayout.WEST, addpanel);
  984. s4.putConstraint(SpringLayout.NORTH, comboTeacher, 220, SpringLayout.NORTH, addpanel);
  985. s4.putConstraint(SpringLayout.WEST, comboReqsub, 30, SpringLayout.WEST, addpanel);
  986. s4.putConstraint(SpringLayout.NORTH, comboReqsub, 270, SpringLayout.NORTH, addpanel);
  987. s4.putConstraint(SpringLayout.WEST, reqbox, 90, SpringLayout.WEST, addpanel);
  988. s4.putConstraint(SpringLayout.NORTH, reqbox, 250, SpringLayout.NORTH, addpanel);
  989. s4.putConstraint(SpringLayout.WEST, addsubject, 220, SpringLayout.WEST, addpanel);
  990. s4.putConstraint(SpringLayout.NORTH, addsubject, 320, SpringLayout.NORTH, addpanel);
  991.  
  992. reqbox.addActionListener(new ActionListener() {
  993.  
  994. @Override
  995. public void actionPerformed(ActionEvent e) {
  996. if (reqbox.isSelected()) {
  997.  
  998. comboReqsub.setVisible(true);
  999. } else {
  1000.  
  1001. comboReqsub.setVisible(false);
  1002. }
  1003.  
  1004. }
  1005. });
  1006.  
  1007. comboReqsub.addActionListener(new ActionListener() {
  1008.  
  1009. @Override
  1010. public void actionPerformed(ActionEvent e) {
  1011. subModel.fireTableDataChanged();
  1012. if (e.getSource() == comboReqsub) {
  1013. JComboBox cb = (JComboBox) e.getSource();
  1014. String ids = (String) cb.getSelectedItem();
  1015.  
  1016. reqsub = getReqSubject(ids);
  1017. }
  1018.  
  1019. }
  1020. });
  1021.  
  1022. addsubject.addActionListener(new ActionListener() {
  1023.  
  1024. @Override
  1025. public void actionPerformed(ActionEvent e) {
  1026.  
  1027. if (addsubname.getText().isEmpty() || addsubroom.getText().isEmpty()) {
  1028. JOptionPane.showMessageDialog(addsubframe, "Nem töltött mindent ki.", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1029.  
  1030. } else if (roomIsTaken()) {
  1031. JOptionPane.showMessageDialog(addsubframe, "A terem foglalt erre az időpontra!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1032.  
  1033. } else if (alreadyExistSub()) {
  1034. JOptionPane.showMessageDialog(addsubframe, "Már létezik ez a kurzus ebben az időpontban!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1035.  
  1036. } else if (teacherIsTeaching()) {
  1037. JOptionPane.showMessageDialog(addsubframe, "A kiválasztott tanár, ebben az időpontban már tanít!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1038.  
  1039. } else {
  1040. Subject newsub = new Subject();
  1041. int id = newsub.hashCode();
  1042. newsub.setId(id);
  1043. newsub.setSubjectName(addsubname.getText());
  1044. newsub.setRoom(addsubroom.getText());
  1045. newsub.setSubDay(comboDay.getSelectedItem().toString());
  1046. newsub.setSubHour(comboHour.getSelectedItem().toString());
  1047. newsub.setTeacherName(comboTeacher.getSelectedItem().toString());
  1048. if (reqbox.isSelected()) {
  1049. newsub.setRequirement(reqsub);
  1050. } else {
  1051. newsub.setRequirement(null);
  1052. }
  1053. newsub.setRegistered_sem(getSelectedSemester());
  1054.  
  1055. DataSource.getInstance().getSubjectController().create(newsub);
  1056. JOptionPane.showMessageDialog(addsubframe, "Tantárgy hozzáadva!", "Információ", JOptionPane.INFORMATION_MESSAGE);
  1057. subModel.fireTableDataChanged();
  1058.  
  1059. currentids = subModel.currentSubjectsId();
  1060. comboId.setModel(new DefaultComboBoxModel<>(currentids));
  1061. comboRequiredarray = (String[]) subModel.currentSubjects();
  1062. comboReqsub.setModel(new DefaultComboBoxModel<>(comboRequiredarray));
  1063. }
  1064.  
  1065. }
  1066.  
  1067. });
  1068.  
  1069. //*********************************** TÁRGY HOZZÁADÁSA VÉGE **********************************************************
  1070. //******************************** TÁRGY TÖRLÉSE *************************************************
  1071. // subModel.fireTableDataChanged();
  1072. currentids = subModel.currentSubjectsId();
  1073. comboId = new JComboBox<>(currentids);
  1074. currentsubname = new JLabel("");
  1075. currentsubroom = new JLabel("");
  1076. currentsubtime = new JLabel("");
  1077. currentsubteacher = new JLabel("");
  1078. currentsubname.setForeground(Color.white);
  1079. currentsubroom.setForeground(Color.white);
  1080. currentsubtime.setForeground(Color.white);
  1081. currentsubteacher.setForeground(Color.white);
  1082. subdetmain.setForeground(Color.white);
  1083. subdetname.setForeground(Color.white);
  1084. subdetroom.setForeground(Color.white);
  1085. subdetteacher.setForeground(Color.white);
  1086. subdettime.setForeground(Color.white);
  1087.  
  1088. subdet.setBackground(Color.WHITE);
  1089. SpringLayout s5 = new SpringLayout();
  1090. subdet.setLayout(s5);
  1091. subdet.add(subdetname);
  1092. subdet.add(subdetroom);
  1093. subdet.add(subdettime);
  1094. subdet.add(comboId);
  1095. subdet.add(subdetmain);
  1096. subdet.add(subdetteacher);
  1097. subdet.add(currentsubname);
  1098. subdet.add(currentsubroom);
  1099. subdet.add(currentsubtime);
  1100. subdet.add(currentsubteacher);
  1101. subdet.add(delete);
  1102. subdet.add(classboard);
  1103.  
  1104. s5.putConstraint(SpringLayout.NORTH, classboard, 0, SpringLayout.NORTH, subdet);
  1105. s5.putConstraint(SpringLayout.WEST, subdetmain, 290, SpringLayout.WEST, subdet);
  1106. s5.putConstraint(SpringLayout.NORTH, subdetmain, 30, SpringLayout.NORTH, subdet);
  1107. s5.putConstraint(SpringLayout.WEST, subdetname, 30, SpringLayout.WEST, subdet);
  1108. s5.putConstraint(SpringLayout.NORTH, subdetname, 75, SpringLayout.NORTH, subdet);
  1109. s5.putConstraint(SpringLayout.WEST, subdetroom, 30, SpringLayout.WEST, subdet);
  1110. s5.putConstraint(SpringLayout.NORTH, subdetroom, 94, SpringLayout.NORTH, subdet);
  1111. s5.putConstraint(SpringLayout.WEST, subdettime, 30, SpringLayout.WEST, subdet);
  1112. s5.putConstraint(SpringLayout.NORTH, subdettime, 135, SpringLayout.NORTH, subdet);
  1113. s5.putConstraint(SpringLayout.WEST, comboId, 420, SpringLayout.WEST, subdet);
  1114. s5.putConstraint(SpringLayout.NORTH, comboId, 30, SpringLayout.NORTH, subdet);
  1115. s5.putConstraint(SpringLayout.WEST, subdetteacher, 30, SpringLayout.WEST, subdet);
  1116. s5.putConstraint(SpringLayout.NORTH, subdetteacher, 115, SpringLayout.NORTH, subdet);
  1117. s5.putConstraint(SpringLayout.WEST, currentsubname, 125, SpringLayout.WEST, subdet);
  1118. s5.putConstraint(SpringLayout.NORTH, currentsubname, 75, SpringLayout.NORTH, subdet);
  1119. s5.putConstraint(SpringLayout.WEST, currentsubroom, 125, SpringLayout.WEST, subdet);
  1120. s5.putConstraint(SpringLayout.NORTH, currentsubroom, 95, SpringLayout.NORTH, subdet);
  1121. s5.putConstraint(SpringLayout.WEST, currentsubtime, 125, SpringLayout.WEST, subdet);
  1122. s5.putConstraint(SpringLayout.NORTH, currentsubtime, 135, SpringLayout.NORTH, subdet);
  1123. s5.putConstraint(SpringLayout.WEST, currentsubteacher, 125, SpringLayout.WEST, subdet);
  1124. s5.putConstraint(SpringLayout.NORTH, currentsubteacher, 115, SpringLayout.NORTH, subdet);
  1125. s5.putConstraint(SpringLayout.WEST, delete, 190, SpringLayout.WEST, subdet);
  1126. s5.putConstraint(SpringLayout.NORTH, delete, 200, SpringLayout.NORTH, subdet);
  1127.  
  1128. comboId.addActionListener(new ActionListener() {
  1129.  
  1130. @Override
  1131. public void actionPerformed(ActionEvent e) {
  1132. if (e.getSource() == comboId) {
  1133. JComboBox cb = (JComboBox) e.getSource();
  1134. String ids = (String) cb.getSelectedItem();
  1135. String[] seged = delsubDetalis(ids);
  1136. currentsubname.setText(seged[0]);
  1137. currentsubroom.setText(seged[1]);
  1138. currentsubtime.setText(seged[2]);
  1139. currentsubteacher.setText(seged[3]);
  1140.  
  1141. }
  1142.  
  1143. }
  1144. });
  1145.  
  1146. delete.addActionListener(new ActionListener() {
  1147.  
  1148. @Override
  1149. public void actionPerformed(ActionEvent e) {
  1150. String ids = (String) comboId.getSelectedItem();
  1151. int realid = Integer.parseInt(ids);
  1152.  
  1153. if (comboId.getItemCount() < 1) {
  1154. subdetailsframe.dispose();
  1155. JOptionPane.showMessageDialog(teacherframe, "Nincs több tantárgy!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1156. } else if (subModel.isThisSubejtARequirent(subModel.getmySubject(realid))) {
  1157. JOptionPane.showMessageDialog(teacherframe, "Ez a tárgy több másik tárgy előfeltétele! pl.:(" + subModel.whatIsThisSubject(subModel.getmySubject(realid)) + ")", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1158. } else {
  1159. ids = (String) comboId.getSelectedItem();
  1160. realid = Integer.parseInt(ids);
  1161.  
  1162. List<PlutoUser> theyhaveit = userModel.theyHaveThisSubject(realid);
  1163.  
  1164. for (int i = 0; i < subModel.getRowCount(); i++) {
  1165. Subject sub = DataSource.getInstance().getSubjectController().findSubjectEntities().get(i);
  1166.  
  1167. if (sub.getId() == realid) {
  1168. if (theyhaveit.isEmpty()) {
  1169. subModel.deleteThisSubject(Integer.parseInt(comboId.getSelectedItem().toString()));
  1170. comboId.removeItem(comboId.getSelectedItem());
  1171. subModel.fireTableDataChanged();
  1172. } else {
  1173. for (int j = 0; j < theyhaveit.size(); j++) {
  1174. userModel.updateHisList(theyhaveit.get(j), sub.getId());
  1175. subModel.fireTableDataChanged();
  1176. userModel.fireTableDataChanged();
  1177. }
  1178. subModel.deleteThisSubject(realid);
  1179. comboId.removeItem(comboId.getSelectedItem());
  1180. }
  1181.  
  1182. }
  1183.  
  1184. }
  1185.  
  1186. }
  1187.  
  1188. }
  1189. });
  1190.  
  1191. //******************************** TÁRGY TÖRLÉSE VÉGE *************************************************
  1192. activstudentsbutton.addActionListener(new ActionListener() {
  1193.  
  1194. @Override
  1195. public void actionPerformed(ActionEvent e) {
  1196. if (userModel.currentstudent().length == 0) {
  1197. JOptionPane.showMessageDialog(teacherframe, "Nincs aktív hallgató az adatbázisban!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1198. } else {
  1199. Object[] currentstudent = userModel.currentstudent();
  1200. String s = (String) JOptionPane.showInputDialog(
  1201. teacherframe,
  1202. "Válasszon hallgatót: ",
  1203. "Hallgatók",
  1204. JOptionPane.PLAIN_MESSAGE,
  1205. null,
  1206. currentstudent,
  1207. currentstudent[0]);
  1208.  
  1209. if (s != null) {
  1210. String[] str = s.split("-");
  1211. doneuser = userModel.getThisUser(str[1]);
  1212.  
  1213. if (doneuser.getSubjects().isEmpty()) {
  1214. JOptionPane.showMessageDialog(teacherframe, "Nincs a hallgatónak tárgya!", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1215. } else {
  1216. JFrame frame = new JFrame();
  1217.  
  1218. DefaultListModel model = new DefaultListModel<>();
  1219. for (int i = 0; i < doneuser.getSubjects().size(); i++) {
  1220. model.addElement(doneuser.getSubjects().get(i).getId() + " - " + doneuser.getSubjects().get(i).getSubjectName() + " - " + doneuser.getSubjects().get(i).getSubDay() + " " + doneuser.getSubjects().get(i).getSubHour());
  1221. }
  1222.  
  1223. list = new JList(model);
  1224. JScrollPane asd = new JScrollPane(list);
  1225. frame.add(asd);
  1226.  
  1227. JButton done = new JButton("Teljesít");
  1228.  
  1229. done.addActionListener(new ActionListener() {
  1230.  
  1231. @Override
  1232. public void actionPerformed(ActionEvent e) {
  1233.  
  1234. String str = list.getSelectedValue().toString();
  1235. String[] strarray = str.split(" - ");
  1236. Subject thiss = subModel.getmySubject(Integer.parseInt(strarray[0]));
  1237.  
  1238. if (userModel.alreadyDoneTHisSubject(thiss.getId(), doneuser)) {
  1239. JOptionPane.showMessageDialog(teacherframe, "Már teljesítette ezt a hallgató", "Hiba történt!", JOptionPane.ERROR_MESSAGE);
  1240. } else {
  1241. userModel.addThisIdToMyList(doneuser, thiss.getId());
  1242. JOptionPane.showMessageDialog(teacherframe, "A(z) " + doneuser.getUsername() + " nevű hallgató mostmár teljesítette a(z) " + strarray[1] + " tárgyat!", "Sikeres tárgy teljesítés!", JOptionPane.INFORMATION_MESSAGE);
  1243. }
  1244.  
  1245. }
  1246. });
  1247.  
  1248. frame.add(done, BorderLayout.PAGE_END);
  1249. frame.setSize(400, 200);
  1250. frame.setVisible(true);
  1251.  
  1252. }
  1253.  
  1254. }
  1255.  
  1256. }
  1257. }
  1258.  
  1259. });
  1260.  
  1261. exitbutton.addActionListener(new ActionListener() {
  1262.  
  1263. @Override
  1264. public void actionPerformed(ActionEvent e) {
  1265. //teacherframe.dispose();
  1266. teacherframe.setVisible(false);
  1267. JFrame start = new PlutoFrame();
  1268. }
  1269. });
  1270.  
  1271. }
  1272.  
  1273. public String[] delsubDetalis(String id) {
  1274. String[] det = new String[5];
  1275. for (int i = 0; i < subModel.getRowCount(); i++) {
  1276. Subject sub = DataSource.getInstance().getSubjectController().findSubjectEntities().get(i);
  1277. if (sub.getId() == Integer.parseInt(id)) {
  1278. det[0] = sub.getSubjectName();
  1279. det[1] = sub.getRoom();
  1280. det[2] = sub.getSubDay();
  1281. det[3] = sub.getSubHour();
  1282. det[4] = sub.getTeacherName();
  1283.  
  1284. }
  1285. }
  1286.  
  1287. return det;
  1288. }
  1289.  
  1290. public boolean alreadyExistSub() {
  1291. boolean exist = false;
  1292. int size = subModel.getRowCount();
  1293. int i = 0;
  1294. while (i < size) {
  1295. Subject sub = DataSource.getInstance().getSubjectController().findSubjectEntities().get(i);
  1296. if (sub.getSubjectName().equals(addsubname.getText()) && roomIsTaken() && teacherIsTeaching()) {
  1297. exist = true;
  1298. }
  1299. i++;
  1300. }
  1301. return exist;
  1302.  
  1303. }
  1304.  
  1305. public boolean roomIsTaken() {
  1306. boolean taken = false;
  1307. int size = subModel.getRowCount();
  1308. int i = 0;
  1309. while (i < size) {
  1310. Subject sub = DataSource.getInstance().getSubjectController().findSubjectEntities().get(i);
  1311. if (addsubroom.getText().equals(sub.getRoom()) && comboDay.getSelectedItem().toString().equals(sub.getSubDay()) && comboHour.getSelectedItem().toString().equals(sub.getSubHour())) {
  1312. taken = true;
  1313. }
  1314. i++;
  1315. }
  1316.  
  1317. return taken;
  1318.  
  1319. }
  1320.  
  1321. public boolean teacherIsTeaching() {
  1322. boolean teach = false;
  1323. int size = subModel.getRowCount();
  1324. int i = 0;
  1325.  
  1326. while (i < size) {
  1327. Subject sub = DataSource.getInstance().getSubjectController().findSubjectEntities().get(i);
  1328. if (comboTeacher.getSelectedItem().toString().equals(sub.getTeacherName()) && comboDay.getSelectedItem().toString().equals(sub.getSubDay()) && comboHour.getSelectedItem().toString().equals(sub.getSubHour())) {
  1329. teach = true;
  1330. }
  1331. i++;
  1332. }
  1333. return teach;
  1334. }
  1335.  
  1336. public int getSelectedSemester() {
  1337. int sem = 0;
  1338.  
  1339. if (comboSemester.getSelectedItem().toString().equals("1.félév")) {
  1340. sem = 1;
  1341. } else if (comboSemester.getSelectedItem().toString().equals("2.félév")) {
  1342. sem = 2;
  1343. } else if (comboSemester.getSelectedItem().toString().equals("3.félév")) {
  1344. sem = 3;
  1345. } else if (comboSemester.getSelectedItem().toString().equals("4.félév")) {
  1346. sem = 4;
  1347. } else if (comboSemester.getSelectedItem().toString().equals("5.félév")) {
  1348. sem = 5;
  1349. } else {
  1350. sem = 6;
  1351. }
  1352.  
  1353. return sem;
  1354.  
  1355. }
  1356.  
  1357. public String getSubjectTime() {
  1358. return comboDay.getSelectedItem() + " " + comboHour.getSelectedItem();
  1359. }
  1360.  
  1361. public Subject getReqSubject(String name) {
  1362. Subject reqsubb = new Subject();
  1363. for (int i = 0; i < subModel.getRowCount(); i++) {
  1364. Subject sub = DataSource.getInstance().getSubjectController().findSubjectEntities().get(i);
  1365. if (sub.getSubjectName().equals(name)) {
  1366. reqsubb = sub;
  1367. }
  1368.  
  1369. }
  1370. return reqsubb;
  1371. }
  1372.  
  1373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement