/** * Add the menus into the menu bar * * @param menuBar The menu bar */ public void initMenuBar(JMenuBar menuBar) { stationModelMenu = new JMenu("Layout Models"); stationModelMenu.addMenuListener( new MenuListener() { public void menuCanceled(MenuEvent e) {} public void menuDeselected(MenuEvent e) {} public void menuSelected(MenuEvent e) { makeStationModelMenu(); } }); fileMenu = new JMenu("File"); fileMenu.addMenuListener( new MenuListener() { public void menuCanceled(MenuEvent e) {} public void menuDeselected(MenuEvent e) {} public void menuSelected(MenuEvent e) { makeFileMenu(); } }); menuBar.add(fileMenu); super.initMenuBar(menuBar); menuBar.add(stationModelMenu); JMenu helpMenu = new JMenu("Help"); JMenuItem helpMenuItem = new JMenuItem("Layout Models"); helpMenu.add(helpMenuItem); helpMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { showHelp(); } }); menuBar.add(helpMenu); }
public SearchPatient(final String type, final int docID) { try { // "Load" the JDBC driver Class.forName("java.sql.Driver"); // Establish the connection to the database String url = "jdbc:mysql://localhost:3306/cse"; conn = DriverManager.getConnection(url, "root", "admin"); } catch (Exception e) { System.err.println("Got an exception!"); System.err.println(e.getMessage()); } // Menu // MENU ACTIONS // Action to view new patient registered class NewPatientAction extends AbstractAction { private static final long serialVersionUID = 1L; public NewPatientAction() { putValue(SHORT_DESCRIPTION, "View list of new patients"); } public void actionPerformed(ActionEvent e) { ViewRegisteredPatients vp = new ViewRegisteredPatients("new"); vp.setVisible(true); ViewRegisteredPatients.hasNew = false; } } Action newPatientAction = new NewPatientAction(); // Action to view all patient registered class AllPatientAction extends AbstractAction { private static final long serialVersionUID = 1L; public AllPatientAction() { putValue(SHORT_DESCRIPTION, "View list of all patients"); } public void actionPerformed(ActionEvent e) { ViewRegisteredPatients vp = new ViewRegisteredPatients("all"); vp.setVisible(true); } } Action allPatientAction = new AllPatientAction(); // Action to open Statistical Report class StatsReportAction implements MenuListener { public void menuSelected(MenuEvent e) { StatsReport report = new StatsReport(); setAlwaysOnTop(false); report.setVisible(true); report.setAlwaysOnTop(true); } public void menuDeselected(MenuEvent e) {} public void menuCanceled(MenuEvent e) {} } // Action to open Statistical Report class ProfileAction implements MenuListener { public void menuSelected(MenuEvent e) { Profile profilePage = new Profile("staff", docID, type); profilePage.setVisible(true); dispose(); } public void menuDeselected(MenuEvent e) {} public void menuCanceled(MenuEvent e) {} } // MENU COMPONENTS menu = new JMenuBar(); menuOp1 = new JMenu(); menuOp2 = new JMenu(); menuOp3 = new JMenu(); menuOp4 = new JMenu(); menuOp5 = new JMenu(); menuOp1.setText("Profile"); menuOp1.addMenuListener(new ProfileAction()); optionsFrame = new JFrame("Options"); optionsContainer = new JPanel(); optionsContainer.setLayout(new BoxLayout(optionsContainer, BoxLayout.Y_AXIS)); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); if (type.equals("Doctor")) // if a doctor is logging in { menuOp2.setText("Patients"); menuOp3.setText("Appointments Request"); menuOp4.setText("View Medical Alerts"); menuItem1 = new JMenuItem("Search Patient"); menuOp2.add(menuItem1); menu.add(menuOp1); menu.add(menuOp2); menu.add(menuOp3); menu.add(menuOp4); // optionsFrame optionUpdateHCC = new JLabel("Update Healthcare Condition"); optionUpdateHCC.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionUpdateHCC.addMouseListener(new MouseUpdateHCCListener()); optionPrescription = new JLabel("e-Prescription"); optionPrescription.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // optionPrescription.addMouseListener(new MousePrescriptionListener()); optionLabRecord = new JLabel("View Lab Records"); optionLabRecord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionLabRecord.addMouseListener(new MouseLabRecordListener()); optionUpdateHCR = new JLabel("Update Healthcare Records"); optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener()); // add option to container optionsContainer.add(optionUpdateHCC); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionPrescription); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionLabRecord); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionLabRecord); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionUpdateHCR); } else if (type.equals("HSP")) // if the HSP is logging in { menuOp2.setText("Patients"); menuOp3.setText("Appointment Request"); menuOp4.setText("View Medical Alerts"); menuOp5.setText("Generate Statistical Report"); menuOp5.addMenuListener(new StatsReportAction()); menuItem1 = new JMenuItem("Search Patient"); menuOp6 = new JMenu("List of Registered Patient"); menuOp6.setMnemonic(KeyEvent.VK_S); menuItem2 = new JMenuItem(newPatientAction); menuItem2.setText("List of New Registered Patient"); menuItem3 = new JMenuItem(allPatientAction); menuItem3.setText("List of All Registered Patient"); menuOp2.add(menuItem1); menuOp2.add(menuOp6); menuOp6.add(menuItem2); menuOp6.add(menuItem3); menu.add(menuOp1); menu.add(menuOp2); menu.add(menuOp3); menu.add(menuOp4); menu.add(menuOp5); // optionsFrame optionUpdateHCC = new JLabel("Update Healthcare Condition"); optionUpdateHCC.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionUpdateHCC.addMouseListener(new MouseUpdateHCCListener()); optionLabRecord = new JLabel("View Lab Records"); optionLabRecord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionLabRecord.addMouseListener(new MouseLabRecordListener()); optionHCR = new JLabel("Upload Healthcare Records"); optionHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionHCR.addMouseListener(new MouseUploadHCRListener()); optionUpdateHCR = new JLabel("Update Healthcare Records"); optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener()); // add option to container optionsContainer.add(optionUpdateHCC); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionLabRecord); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionLabRecord); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionHCR); optionsContainer.add(Box.createRigidArea(new Dimension(20, 5))); optionsContainer.add(optionUpdateHCR); } else if (type.equals("Pharmacist")) // if the Pharmacist is logging in { menuOp2.setText("Patients"); menuItem1 = new JMenuItem("Search Patients"); menuOp2.add(menuItem1); menu.add(menuOp1); menu.add(menuOp2); // optionsFrame optionViewPrescription = new JLabel("View e-Prescription"); optionViewPrescription.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionViewPrescription.addMouseListener(new MouseViewPrescriptionListener()); // add option to container optionsContainer.add(optionViewPrescription); } else if (type.equals("Nurse")) // if the nurse is logging in { menuOp2.setText("Patients"); menuItem1 = new JMenuItem("Search Patients"); menuOp2.add(menuItem1); menu.add(menuOp1); menu.add(menuOp2); // optionsFrame optionUpdateHCR = new JLabel("Update Healthcare Records"); optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener()); // add option to container optionsContainer.add(optionUpdateHCR); } // Labels firstNameLabel = new JLabel(" First name:"); // first name label lastNameLabel = new JLabel("Last name:"); // last name label patientListLabel = new JLabel("Patient List:"); // patient list label // Text Fields firstNameField = new JTextField(10); // first name text field lastNameField = new JTextField(10); // last name text field // Buttons searchButton = new JButton("Search"); // search button searchButton.addActionListener(new SearchButtonListener()); // add listener selectButton = new JButton("Select"); selectButton.addActionListener(new SelectButtonListener()); // add listener cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new CancelButtonListener()); // add listener // JPanels firstNamePanel = new JPanel(); // First name panel firstNamePanel.add(firstNameLabel); firstNamePanel.add(firstNameField); lastNamePanel = new JPanel(); // Last name panel lastNamePanel.add(lastNameLabel); lastNamePanel.add(lastNameField); patientInfoPanel = new JPanel(); patientInfoPanel.setLayout(new BoxLayout(patientInfoPanel, BoxLayout.X_AXIS)); patientInfoPanel.add(firstNamePanel); patientInfoPanel.add(lastNamePanel); patientInfoPanel.add(searchButton); buttonPanel = new JPanel(); // button panel buttonPanel.add(selectButton); buttonPanel.add(cancelButton); // Patient List patientVector = new Vector(); // Vector of Patient objects patientList = new JList(patientVector); // creates a JList that show the content of the recordVector scrollPatientList = new JScrollPane(patientList); // add scroll option to the list patientList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION); // Allow the selection of only one item at a time String[] patients = new String[1000000]; // Populates the patient list with the patients from the database if (type.equals("Doctor")) { int i = 0; try { // checks if the patient is a patient of the doctor logged statement = conn.createStatement(); rs = statement.executeQuery( "SELECT * FROM appointments WHERE `docID`='" + docID + "' ORDER BY `patientID`"); while (rs.next()) { int patientID = rs.getInt("patientID"); patients[i] = String.valueOf(patientID); i++; } String[] patientSet = (String[]) new HashSet(Arrays.asList(patients)).toArray(new String[0]); // gets information from the specific set of patients for (int j = 0; j < patientSet.length; j++) { statement = conn.createStatement(); rs = statement.executeQuery( "SELECT * FROM patient WHERE `idpatient`='" + patientSet[j] + "';"); while (rs.next()) { Patient obj = new Patient(); obj.setFirstName(rs.getString("fname")); obj.setLastName(rs.getString("lname")); obj.setDOB(rs.getString("dob")); obj.setPatientId(Integer.parseInt(patientSet[j])); patientVector.add(obj); } } } catch (Exception e) { System.err.println("Got an exception! "); System.err.println(e.getMessage()); System.err.println(e); } } else { try { statement = conn.createStatement(); rs = statement.executeQuery("SELECT * FROM patient ORDER BY fname"); while (rs.next()) { Patient obj = new Patient(); obj.setFirstName(rs.getString("fname")); obj.setLastName(rs.getString("lname")); obj.setDOB(rs.getString("dob")); obj.setPatientId(rs.getInt("idpatient")); patientVector.add(obj); } } catch (Exception e) { System.err.println("Got an exception! "); System.err.println(e.getMessage()); } } searchVector = new Vector(); // set options frame optionsFrame.add(optionsContainer); optionsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // close the window on close optionsFrame.setSize(300, 150); // set size of window optionsFrame.setLocation(600, 280); optionsFrame.setVisible(false); searchPanel = new JPanel(); searchPanel.setLayout(new BoxLayout(searchPanel, BoxLayout.Y_AXIS)); searchPanel.add(patientInfoPanel); searchPanel.add(patientListLabel); searchPanel.add(scrollPatientList); searchPanel.add(buttonPanel); Border padding = BorderFactory.createEmptyBorder(20, 20, 10, 10); searchPanel.setBorder(padding); setJMenuBar(menu); add(searchPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(1200, 580); }
public DialogStammdaten(JFrame fenster, String[][] datensatz1, String s, Methoden datenbank1) { super(fenster, true); datenbank = datenbank1; datensatz = datensatz1; p = new JPanel(); platzhalter = new JLabel(); text1 = new JLabel("Name"); text2 = new JLabel("Personalnummer"); text3 = new JLabel("Titel"); text4 = new JLabel("Institut"); feld = new JComboBox(); textName = new JTextField(); textPersonalnr = new JTextField(); textInstitut = new JTextField(); textTitel = new JTextField(); menue = new JMenuBar(); datei = new JMenu("Datei"); aendern = new JMenuItem("Aendern"); hinzufuegen = new JMenuItem("Hinzufuegen"); loeschen = new JMenuItem("Loeschen"); beenden = new JMenuItem("Beenden"); final JDialog dialog = this; this.setTitle(s); feld = new JComboBox(ersteElemente(datensatz)); textName.setText(datensatz[0][0]); textPersonalnr.setText(datensatz[0][1]); setzen(datensatz, feld.getSelectedIndex()); feld.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getID() == ItemEvent.ITEM_STATE_CHANGED && e.getStateChange() == ItemEvent.SELECTED) { textName.setText((String) e.getItem()); textPersonalnr.setText(datensatz[feld.getSelectedIndex()][1]); setzen(datensatz, feld.getSelectedIndex()); } } }); datei.addMenuListener( new MenuListener() { public void menuSelected(MenuEvent e) { hinzufuegen.setEnabled(false); aendern.setEnabled(false); loeschen.setEnabled(false); if (!geaendert(datensatz, feld.getSelectedIndex())) { loeschen.setEnabled(true); } else if (!(textName.getText().equals("") || textPersonalnr.getText().equals(""))) { hinzufuegen.setEnabled(true); aendern.setEnabled(true); } } public void menuDeselected(MenuEvent e) {} public void menuCanceled(MenuEvent e) {} }); hinzufuegen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String[] daten = erstellen(); if (hinzufuegen(daten)) { dispose(); } else { JOptionPane.showMessageDialog( dialog, "Hinzufuegen geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE); } } }); aendern.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String[] daten = erstellen(); if (aendern(datensatz[feld.getSelectedIndex()][1], daten)) { dispose(); } else { JOptionPane.showMessageDialog( dialog, "Aendern geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE); } } }); loeschen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String[] daten = erstellen(); if (loeschen(datensatz[feld.getSelectedIndex()][1])) { dispose(); } else { JOptionPane.showMessageDialog( dialog, "Loeschen geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE); } } }); beenden.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); datei.add(hinzufuegen); datei.add(aendern); datei.add(loeschen); datei.add(beenden); menue.add(datei); this.setJMenuBar(menue); p.setLayout(new GridLayout(2, 5)); p.add(platzhalter); p.add(text1); p.add(text2); p.add(text3); p.add(text4); p.add(feld); p.add(textName); p.add(textPersonalnr); p.add(textTitel); p.add(textInstitut); this.setContentPane(p); this.pack(); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }