Question

In: Computer Science

Write a GUI that allows the user to do the following: Create a new Patient Database...

Write a GUI that allows the user to do the following:

Create a new Patient Database if it doesn’t exist yet by the click of a button.

Create a second button that populates the database with the appropriate Asset table if it does not exist yet, and fill the table with at least 10 patients.

Connect to the Patient Database and display all current patients in a List by default. You will have to create a Patient Class. This class needs at a minimum the following attributes: Name, Id, Age, Gender, Blood type, Weight, Height. Use appropriate data types. (use UUID for the Id property).

Next to the list displaying the patients, create at least three ways to filter that list. For instance, you only want to display patients over the age of 30. Or only patients who are "Female". Or only patients with weight above 200 lbs. Be creative in which filters would make real sense and use appropriate JFoeniX controls for them. Make sure the controls you use send the appropriate SQL Query to the database and display the results in the patients list view.

It needs to be in Java and JavaFX. Does not have any files provided. Just need it in code. Especially for the Patient class

There is no GUI specification. Just a simple one will do.

Solutions

Expert Solution

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.table.DefaultTableModel;
import javax.swing.JMenuBar;
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.*;


public class GUI extends JFrame implements ActionListener {
  
   //Initializing the Panels
   JPanel northPanel= new JPanel();
   JPanel southPanel= new JPanel();
   //End of Initializing Panels
  
  
   //Adding the Welcome Text JLabel
   JLabel welcomeText = new JLabel("Welcome to Lifeline! Pick up your choice from the menu above, or double click on a patient's record.");
   //End of Adding the welcome Text
  
  
   //Initializing the Table
   static JTable patientsTable = new JTable() {
   private static final long serialVersionUID = 1L;

   public boolean isCellEditable(int row, int column) {
   return false; //cells are set to be read-only
   };
   };
  
   static DefaultTableModel model = new DefaultTableModel(){};
   //End of initializing the Table

  
  
   //Initializing the Menus
   JMenuBar menuBar = new JMenuBar();
   JMenu fileMenu = new JMenu("File");
   JMenu patientsMenu = new JMenu("Patients");
   JMenu lifeLineMenu = new JMenu("Lifelines");
   JMenu aboutMenu = new JMenu("About Us");
   JMenu contactMenu = new JMenu("Contact Us");
   //End of Initializing the Menus
  
  
   //Initializing Menus' Items
   JMenuItem fileExit = new JMenuItem("Exit");
   JMenuItem addPatientMenu = new JMenuItem("Add patient");
   JMenuItem removePatientMenu = new JMenuItem("Remove Patient");
   JMenuItem updatePatientMenu = new JMenuItem("Update Patient");
   JMenuItem addLifelineMenu = new JMenuItem("Add a Lifeline Record");
   JMenuItem showLifelineMenu = new JMenuItem("Show the Lifeline of a user");
   JMenuItem showAboutUs = new JMenuItem("Click Here");
   JMenuItem showContactUs = new JMenuItem("Click Here");
   //End of Initializing Menus' Items
  

  
  
   public static void main(String[] args) {
      
      
       GUI graphicUserInterface = new GUI();
       patientsTable.setModel(model);
       loadData();

       }
  
   //Graphical user interface constructor
   public GUI(){
      
       //Adding Menus Mnemonics
       fileMenu.setMnemonic('F');
       patientsMenu.setMnemonic('P');
       lifeLineMenu.setMnemonic('L');
       aboutMenu.setMnemonic('A');
       contactMenu.setMnemonic('C');
       //Adding of adding Menus Mnemonics
         
         
       //GUI specifications
       setLayout(new BorderLayout());
       setSize(800,600);
       setTitle("Lifeline");
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setLocationRelativeTo(null);
       setVisible(true);
       setResizable(false);
       //End of GUI Specifications
         
         
       //Adding JPanels
       add("North", northPanel);
       add("South", southPanel);
       northPanel.add(menuBar);
       //northPanel.setBackground(Color.GRAY);
       //southPanel.setBackground(Color.WHITE);
       southPanel.add(welcomeText);
       //End of adding JPanels
         

       //Adding the Table
       add(new JScrollPane(patientsTable));
       //End of adding the Table
         
         
       //Adding menus to menubar
       menuBar.add(fileMenu);
       menuBar.add( Box.createHorizontalStrut( 30 ) );
       menuBar.add(patientsMenu);
       menuBar.add( Box.createHorizontalStrut( 30 ) );
       menuBar.add(lifeLineMenu);
       menuBar.add( Box.createHorizontalStrut( 30 ) );
       menuBar.add(aboutMenu);
       menuBar.add( Box.createHorizontalStrut( 30 ) );
       menuBar.add(contactMenu);
       //End of adding menus to menu bar
         
       //Adding submenus to menus
       fileMenu.add(fileExit);
       patientsMenu.add(addPatientMenu);
       patientsMenu.add(updatePatientMenu);
       patientsMenu.add(removePatientMenu);
       lifeLineMenu.add(addLifelineMenu);
       lifeLineMenu.add(showLifelineMenu);
       aboutMenu.add(showAboutUs);
       contactMenu.add(showContactUs);
         
       //End of Adding submenus to menus
         
         
       //Adding the ActionListeners
       fileExit.addActionListener(this);
       addPatientMenu.addActionListener(this);
       updatePatientMenu.addActionListener(this);
       removePatientMenu.addActionListener(this);
       addLifelineMenu.addActionListener(this);
       showLifelineMenu.addActionListener(this);
       showAboutUs.addActionListener(this);
       showContactUs.addActionListener(this);
       aboutMenu.addActionListener(this);
       //End of adding the action listeners
         
         
       //Mouse listener for the JTable
       patientsTable.addMouseListener(new MouseAdapter() {
             
             
           public void mousePressed(MouseEvent me) {
          
           int row= patientsTable.getSelectedRow();
          
           if (me.getClickCount() == 2) {
              
               Object[] possibleValues = {"Remove the Patient", "Update the Patient", "Show Lifeline", "Add a Lifeline"};
               Object SelectedValue= JOptionPane.showInputDialog(null, "Choose your option", "Select an Action", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
              
               String id = (String) patientsTable.getModel().getValueAt(row, 0);
              
              
          
               if(SelectedValue=="Remove the Patient"){
                  
                   RemovePatientForm removePatient= new RemovePatientForm();
                   removePatient.setIdText(id);
               }
              
               if(SelectedValue=="Update the Patient"){
              
           UpdatePatientForm updatePatient = new UpdatePatientForm();
             
           String name = (String) patientsTable.getModel().getValueAt(row, 1);
               String surname = (String) patientsTable.getModel().getValueAt(row, 2);
               String birth = (String) patientsTable.getModel().getValueAt(row, 3);
               String blood = (String) patientsTable.getModel().getValueAt(row, 4);
               String phone = (String) patientsTable.getModel().getValueAt(row, 5);
               String email = (String) patientsTable.getModel().getValueAt(row, 6);
               String country = (String) patientsTable.getModel().getValueAt(row, 7);
              
           updatePatient.setAllText(id, name, surname, birth, blood, phone, email, country);
               }
              
               if(SelectedValue=="Show Lifeline"){
                  
                   ShowLifelineRecords record = new ShowLifelineRecords();
                   record.showLifeline(id);
                  
                  
               }
              
               if(SelectedValue=="Add a Lifeline"){
                   AddLifelineRecord add = new AddLifelineRecord();
                   add.setId(id);
               }
           }
           }
           });
         
       //End of the Mouse listener
         
         
         
         
       this.addWindowListener(new WindowAdapter() {
             
           public void windowActivated(WindowEvent e) {
                 
               loadData();
           }
           });
         
         
}
  
  

   public void actionPerformed(ActionEvent arg0) {
      
       if(arg0.getSource()==fileExit){
           System.exit(DO_NOTHING_ON_CLOSE);
       }
      
      
      
  
       if(arg0.getSource()==addPatientMenu){
          
           addPatientForm f1= new addPatientForm();
          
       }
      
       if(arg0.getSource()== updatePatientMenu){
          
           UpdatePatientForm f2 = new UpdatePatientForm();
       }
      
       if(arg0.getSource()==removePatientMenu){
          
           RemovePatientForm f3 = new RemovePatientForm();
       }
      
       if(arg0.getSource()==addLifelineMenu){
          
           AddLifelineRecord f4 = new AddLifelineRecord();
       }
      
       if(arg0.getSource()==showLifelineMenu){
          
           ShowLifelineRecords f5 = new ShowLifelineRecords();
       }

       if(arg0.getSource()== showAboutUs){
          
           AboutUs f6 = new AboutUs();
       }
      
       if(arg0.getSource()==showContactUs){
          
           ContactUs f7 = new ContactUs();
       }
      
      
   }
  
  
   public static void loadData(){
      
       //Connecting to the database
       final String DATABASE_URL="jdbc:mysql://localhost/javaproject";
       Connection connection = null;
       Statement statement = null;
       ResultSet resultSet = null;
       //End of database connection
      
       //Initializing the columns Names
       Object[] columnsName = new Object[8];
  
columnsName[0] = "ID";
columnsName[1] = "Name";
columnsName[2] = "Surname";
columnsName[3] = "Date of Birth (yyyy-mm-dd)";
columnsName[4]="Blood Type";
columnsName[5]="Phone Number";
columnsName[6]="Email";
columnsName[7]="Country";
  
model.setColumnIdentifiers(columnsName);
//End of initializing the columns Names
  
//Getting the data from the database
Object[] rowData = new Object[8];
  
  
try{
          
           connection=DriverManager.getConnection(DATABASE_URL,"root","");
           statement = connection.createStatement();
           resultSet= statement.executeQuery("select * from lifeliners");
          
           model.setRowCount(0);
          
           while(resultSet.next()){
              
               rowData[0] = resultSet.getString("p_id");
               rowData[1] = resultSet.getString("p_name");
               rowData[2] = resultSet.getString("p_surname");
               rowData[3] = resultSet.getString("p_date_of_birth");
               rowData[4] = resultSet.getString("p_blood_type");
               rowData[5] = resultSet.getString("p_phone");
               rowData[6] = resultSet.getString("p_email");
               rowData[7] = resultSet.getString("p_country");
                 
                 
               model.addRow(rowData);
              
          
              
           }
       }

      
       catch(Exception exc){
          
           exc.printStackTrace();
          
       }
//End of getting the data
   }

}


Related Solutions

in java Write a contacts database program that presents the user with a menu that allows...
in java Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
Write a GUI-based program that allows the user to open, edit, and save text files. The...
Write a GUI-based program that allows the user to open, edit, and save text files. The GUI should include a labeled entry field for the filename and multi-line text widget for the text of the file. The user should be able to scroll through the text by manipulating a vertical scrollbar. Include command buttons labeled Open, Save, and New that allow the user to open, save and create new files. The New command should then clear the text widget and...
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number of data set. 2- Allows the user to exit the program at any time by entering zero. 3- Calculates and displays the following statistics for the entered data set: a- Count of positive, negative, and total numbers. b- Maximum and Minimum numbers. c- Sum and Average of positive numbers. d- Sum and Average of negative numbers. e- Overall Sum and overall average of all...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Create a simple python app that allows the user to create a roster of students and...
Create a simple python app that allows the user to create a roster of students and their grade on CUS-1166. Moreover the app needs to calculate the average grade of students added to the roster. 1-To begin with, create a new file n the same working folder as part A (i.e. cus1166_lab1) and name it app.py. Moreover, create a subfolder and name it mymodules. 2-Within mymodules create the files __init__.py , models.py , math_utils.py . 3-In the models.py file define...
Create an application that allows the user to enter the total for an order and the...
Create an application that allows the user to enter the total for an order and the name of the customer. If the order is less than 500 dollars, the customer gets no discount. If the order is greater than or equal to 500 and less than 1000 dollars, the customer gets a 5 percent discount. If the order is greater than or equal to 1000 dollars, the customer gets a 10 percent discount. The application should display the name of...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
PLEASE DO IN C++ Create an object-oriented program that initially allows the user to save customer...
PLEASE DO IN C++ Create an object-oriented program that initially allows the user to save customer information in the list and to search for a customer by specifying the customer’s ID. Sample Run Customer Information Management System --------------------------------------------------------------- CUSTOMER DATA ENTRY: Full Name (First, Last): Jenny Ha Company: Convergent Laser Technologies Street: 1000 International Ave City: Oakland State: CA Zip Code: 94506 ID: 100 Continue Your Data Entry? (y/n): y Full Name (First, Last): Bill Martinez Company: Cisco Systems Street:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT