Trying to add long data type to constructor

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 728 Views - Last Post: 07 May 2013 - 05:31 AM Rate Topic: -----

#1 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Trying to add long data type to constructor

Posted 06 May 2013 - 04:13 AM

I am trying to add a patient as coded below. The phone number in the patient class has been declared as type long. I am getting a message which basically says string..string, int...undefined. So the problem is the phone number -0879233239 it thinks is an int and not long. What do i need to do. I tried adding L to end of 0879233239.
SurgeryMgtSys()
	{
	this.addPatient((new Patient("S","Lons","44 Springfield","14/4/07",0879233239,"692541v", "influenza", "NONE", "Female", "B+"));
	
	}


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to add long data type to constructor

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 199
  • View blog
  • Posts: 1,683
  • Joined: 13-March 10

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:18 AM

Show us the addPatient() method and Patient class.
Was This Post Helpful? 0
  • +
  • -

#3 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:23 AM

import java.awt.Checkbox;
import java.io.Serializable;


public class Patient implements Serializable
{
	private String firstName, surname, address,dob,ppsNumber,history,complaint, bloodgroup;
	private long patientNumber;
	private Checkbox gender;

	

public Patient( String p_Name, String p_surname, String p_Address, String p_dob,  long p_pPhone,
		String p_pps, String p_history, String p_Complaint, Checkbox p_Gender, String p_Bgroup ) 
	{
	
	firstName =  p_Name;//Initializing variables to parameters above
	surname =  p_surname;
	address= p_Address;
	dob = p_dob;
	patientNumber = p_pPhone; 
	ppsNumber = p_pps;
	history = p_history;
	complaint = p_Complaint;
	gender = p_Gender;
	bloodgroup = p_Bgroup;
	
	}

public String getHistory() {
	return history;
}

public void setHistory(String history) {
	this.history = history;
}

public String getComplaint() {
	return complaint;
}

public void setComplaint(String complaint) {
	this.complaint = complaint;
}

public String getBloodgroup() {
	return bloodgroup;
}

public void setBloodgroup(String bloodgroup) {
	this.bloodgroup = bloodgroup;
}

public Checkbox getGender() {
	return gender;
}

public void setGender(Checkbox gender) {
	this.gender = gender;
}

public String getFirstName() 
{
	return firstName;
}
public void setFirstName(String firstName)
{
	this.firstName = firstName;
}
public String getSurname() 
{
	return surname;
}
public void setSurname(String surname) 
{
	this.surname = surname;
}
public String getAddress() 
{
	return address;
}
public void setAddress(String address) 
{
	this.address = address;
}

public String getDob()
{
	return dob;
}
public void setDob(String dob) 
{
	this.dob = dob;
}
public String getPpsNumber() 
{
	return ppsNumber;
}
public void setPpsNumber(String ppsNumber) 
{
	this.ppsNumber = ppsNumber;
}
public long getPatientNumber()
{
	return patientNumber;
}
public void setPatientNumber(long patientNumber) 
{
	this.patientNumber = patientNumber;
}

}

public void addPatient(Patient p) 

	{
	
	//adding patient and patient detail to the patient list arraylist
	PatientList.add(p);
	this.printPatientArrayListDetToConsole(PatientList);
	
	} 

Was This Post Helpful? 0
  • +
  • -

#4 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 199
  • View blog
  • Posts: 1,683
  • Joined: 13-March 10

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:29 AM

Why do you think the problem is with long. Have you tried deleting it and seeing whether the problem is still there? I would say problem is with CheckBox.
Was This Post Helpful? 0
  • +
  • -

#5 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:31 AM

The constructor Patient(String, String, String, String, int, String, String, String, String, String) is undefined
therefore i think there is a problem with both of them as the long is showing up as int as the checkbox is showing up as string. How do i correct this?
Was This Post Helpful? 0
  • +
  • -

#6 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 199
  • View blog
  • Posts: 1,683
  • Joined: 13-March 10

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:33 AM

What is CheckBox meant to represent? It's a visual component so there should be some data behind it. And dont use java.awt package. It's old. Check out javax.swing.
Was This Post Helpful? 0
  • +
  • -

#7 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:36 AM

Checkbox is so that user can enter the choice.
cbmf=new CheckboxGroup();
    	cbm=new Checkbox("Male",cbmf,true);
    	cbf=new Checkbox("Female",cbmf,false);
    	cbm.setBounds(698,223,50,15);
    	addpatientPanel.add(cbm);
    	cbf.setBounds(760,223,60,15);
    	addpatientPanel.add(cbf);

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3253
  • View blog
  • Posts: 10,908
  • Joined: 12-December 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:43 AM

View Postmattylynch1, on 06 May 2013 - 11:31 AM, said:

The constructor Patient(String, String, String, String, int, String, String, String, String, String) is undefined
therefore i think there is a problem with both of them as the long is showing up as int as the checkbox is showing up as string. How do i correct this?

You are passing the value "NONE" to your constructor, which is a String, not a Checkbox. The error message tells you that you do not have a constructor with this set of parameters:

Quote

Patient(String, String, String, String, int, String, String, String, String, String)

As a separate issue, I would store the phone number as a String, particularly as you want to keep the leading 0 (and maybe spaces and hyphens). A phone number is not really a number; after all, you never sum it.

This post has been edited by andrewsw: 06 May 2013 - 04:48 AM

Was This Post Helpful? 3
  • +
  • -

#9 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 04:45 AM

Im just going to create another constructor to initially manually add a couple of patients to arraylist.
Was This Post Helpful? 0
  • +
  • -

#10 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 11:22 AM

I have a table with rows containing names of patients. I want to click on a name in the table and different attributes will display in box below depending on the patient clicked.Here is what ive done so far. I dont know if what ive done is correct.In the guiclass where the table resides i have added listeners as shown.needless to say its not working. Could someone explain what needs to be done. Im confused with it all.
//Adding listeners for the table data.
	 void rowClickListener(TableModelListener listenForMouseClickonRow)
	 {
		 table.addMouseListener((MouseListener) listenForMouseClickonRow);
		 //table.getModel().addTableModelListener(listenForMouseClickonRow);
	 }

then in my controller class i have added a class IT has forced me to add all these events which i dont even want.
public class rowClickListener implements MouseListener
	{
	
		@Override
		public void mouseClicked(MouseEvent e) {
			if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1)
			{
				System.out.println("TEST mouse click");
			}
			
		}

		

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}



		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
	}

Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,479
  • Joined: 27-December 08

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 12:27 PM

It's really not good practice to name your Listener class and a method the same thing. For some basic debugging purposes, put println() statements in each of the Listener methods and see if anything prints. Another point as well- why aren't you adding an instance of rowClickListener as your MouseListener?

Also, a TableModelListener isn't a MouseListener.
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 12:47 PM

I always use a MouseListener to change JCheckBox in a JTable

	TableColumn tci = tcm.getColumn(COL_CHECKBOX); 

	// the JCheckBox to edit that column through the MouseAdapter thought not woth editor
	selectedCheckBox = new JCheckBox();
	selectedCheckBox.setBackground(Color.WHITE);
	selectedCheckBox.setOpaque(true);
	selectedCheckBox.setHorizontalAlignment(SwingConstants.CENTER);		
	tci.setMaxWidth(40);                // no need to make it too big




	 /* 
	 * Used to edit the JCheckedBox on the last column
	 */
	class MousePressed extends MouseAdapter {
		// react to a mouseClick
		public void mouseClicked(MouseEvent me) {
			// don't react if the user is too nervous
			if(me.getClickCount() != 1)
				return;

			// OK is thge click on the only column driven by a mouseClick
			Point p = me.getPoint();
			int col = columnAtPoint(p);
			if(col != COL_CHECKBOX)
				return;

			// OK so get the row, the correponding book
			int row = rowAtPoint(p);

 			// from my arrayList of Book in my model
			Book book = bookArray.get(row);
			// switch its selected status
			book.bIsSelected = !book.bIsSelected;
			// and repaint it
			bookModel.fireTableCellUpdated(row, col);
		}



	// Returns the correct JLabel from my Book object
	// or the JCheckBox for the Slect column
	public Component getTableCellRendererComponent(JTable table, Object obj,
			boolean isSelected, boolean hasFocus, int row, int col) {
		// OK normal case
		Book book = (Book) obj; 
		switch(col) {
			case COL_ID:
				return book.getIdLabel(isSelected);
			case COL_TITLE:
				return book.getTitleLabel(isSelected);
			case COL_DATE:
				return book.getDateLabel(isSelected);
			case COL_SIZE:
				return book.getLengthLabel(isSelected);
				// for the last column we return the JCheckBox set or not depending on that book
			case COL_CHECKBOX:
				selectedCheckBox.setSelected(book.bIsSelected);
				return selectedCheckBox;
		}



Happy coding
Was This Post Helpful? 1
  • +
  • -

#13 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 01:02 PM

Ive added print statmenents but nothing is happening so the listener is not getting added but i still cant figure out why.Ive also changed it to a mouse listener.
void rowClickListener(MouseListener listenForMouseClickonRow)
	 {
		 System.out.println("TEST test test");
		 table.addMouseListener( listenForMouseClickonRow);
		 
		 //table.getModel().addTableModelListener(listenForMouseClickonRow);
	 }

Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,479
  • Joined: 27-December 08

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 01:04 PM

Please post a minimal viable sample. That is, something I can run and see the problem without extraneous code.
Was This Post Helpful? 1
  • +
  • -

#15 mattylynch1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 27-November 12

Re: Trying to add long data type to constructor

Posted 06 May 2013 - 01:11 PM

Is this too much. Unsure what to give. Im fairly inexperienced to say the least!
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

public class Controller 
{
	
	 private LoginGUI lGUI;
	 private DocAppMainGUI DAMGUI;
	 private AddPatientGui APG;
	 private SurgeryMgtSys SMS;
	 

public Controller(LoginGUI lGui,DocAppMainGUI DAMGui,AddPatientGui apg,SurgeryMgtSys sms) 
{

    this.lGUI = lGui;
    this.DAMGUI = DAMGui;
    this.APG = apg;
    this.SMS = sms;
    
    //Here we populate an arraylist with some patients and add them to the table in the MainGUI.
    SMS.addPatient(new Patient("Simon","Petr","44 Springfield","14/4/07","0879233239","692541v", "influenza", "NONE", "Female", "B+"));
    SMS.addPatient(new Patient("Phil Jr","Woods","44 Springfield","16/2/13","0879233239","692541v", "influenza", "NONE", "male", "B+"));
    
    for (Patient P : SMS.PatientList) 
    {
    	//Declaring variables to hold values which will also be outputted to table 
    			String firstName = P.getFirstName();
    			String surName = P.getSurname();
    			String gender = P.getGend();
    			String addressField = P.getAddress();
    			String dob = P.getDob();
    			String bloodGroup = P.getBloodgroup();
    			String patientPhoneNo = P.getPatientNum();
    			String ppsNo = P.getPpsNumber();
            DefaultTableModel model =(DefaultTableModel) DAMGUI.getTable().getModel();
            model.addRow(new Object[] { firstName,surName, gender,addressField,dob,bloodGroup,patientPhoneNo, ppsNo, });
    }
   

    
   // lGUI.createAndShowLoginGUI();
    //APG.createAndShowaddPatientGUI();
    DAMGUI.createAndShowDocAppMainGUI();
   
    // Tell the LoginGUI(View) that when ever the login button
    // is clicked to execute the actionPerformed method
    // in the LoginListener inner class
    
    lGUI.addLoginListener(new LoginListener());
    DAMGUI.addPatientListener(new PatientListener());
    DAMGUI.BackupListener(new BackupRestoreListener());
    APG.newPatientListener(new NewPatientListener());

  
}
//Listeners for login button/cancel button on the login GUI.
public class LoginListener implements ActionListener
{
	
	 public void actionPerformed(ActionEvent login)
	 {
		 
		 //System.out.println(lGUI.getClass());
	        if(login.getSource() == lGUI.loginButton)
	        {
	        	
	        	String pass = new String(lGUI.passwordField.getPassword());

	            if(lGUI.usernameField.getText().compareTo("Matt") == 0 &&  pass.compareTo("password") == 0)
	            {
	            	
	            	JOptionPane.showMessageDialog( null, "Logging in.....");
	            	//LoginGUI.setVisible(false);
	            	//lGUI.frame.dispose();
	            	//DocAppMainGUI damg = new DocAppMainGUI();
	            	
	            	DAMGUI.createAndShowDocAppMainGUI();
	            	lGUI.dispose();
	            }
	            
	            else
	            {
	            	JOptionPane.showMessageDialog( null, "Incorrect Details, Please check and try again" );
	            }

	        }
	        if(login.getSource() == lGUI.cancelButton) 
	        	lGUI.dispose();
	    }

	
	
	}
//Listeners for the add/search/update listeners on DocAppMain GUI Form
	public class PatientListener implements ActionListener
	{

		public void actionPerformed(ActionEvent patient) 
	    {
			 if(patient.getSource() == DAMGUI.addNew) 
			 {
				 JOptionPane.showMessageDialog(null, "Adding New Patient") ;
				 APG.createAndShowaddPatientGUI();
			 }
			 if (patient.getSource() ==DAMGUI.searchPatient)
			 {
				 JOptionPane.showMessageDialog(null, "Enter Patients Surname") ;
			 }
			 if (patient.getSource() ==DAMGUI.updatePatient)
			 {
				 JOptionPane.showMessageDialog(null, "Documenting patients visit.") ;
				
			 }
			 if (patient.getSource() ==DAMGUI.searchCriteriaComboBox)
			 {
				 JOptionPane.showMessageDialog(null, "Searching by relevant criteria.") ; 
			 }
	        
	     }
	}
	
	
	//listener for add/cancel/clear buttons within the addpatient form.
	public class NewPatientListener implements ActionListener
	{

		
		public void actionPerformed(ActionEvent listenforClickAddEdit)
		 {
			//Add patient button
			if (listenforClickAddEdit.getSource() == APG.addBut)
			{
				try 
				{
				String firstName = APG.patientFirstNameField.getText();
				String surName = APG.patientSurnameField.getText();
				String addressField = APG.addressField.getText();
				String dob = APG.dobfield.getText();
				Long patientPhoneNo = Long.parseLong(APG.PatientNoField.getText());
				String ppsNo =APG.ppsField.getText();
				String history = APG.hisField.getText();
				String allergies = APG.allergies.getText();
				Checkbox gender = APG.cbmf.getSelectedCheckbox();
				String bloodGroup = APG.chbg.getSelectedItem();
				
				SMS.addPatient(new Patient(firstName,surName,addressField,dob,patientPhoneNo,ppsNo, history, allergies, gender, bloodGroup));
				SMS.addPatienthistory(new PatientHistory (history,allergies));
				JOptionPane.showMessageDialog(null, "Adding New Patient to database:" +  APG.patientFirstNameField.getText() + " " + APG.patientSurnameField.getText() );
				//Creating instance of TableModel and adding the variables to it in the rows.
				DefaultTableModel model =(DefaultTableModel) DAMGUI.getTable().getModel();
				model.addRow(new Object[] { firstName,surName, gender,addressField,dob,bloodGroup,patientPhoneNo, ppsNo, });
				
				//Setting the historical areas on mainGui to history and allergy for patient just added.
				DAMGUI.prevconditionArea.setText(history);
				DAMGUI.allergyArea.setText(allergies);
				
				
				}
				
				catch(NumberFormatException ex)
				{
	            	System.out.println(ex);
	                SMS.displayErrorMessage("Please ensure all fields have values and are filled correctly");
				}
				
			}
			//JOptionPane.showMessageDialog(null, "Patttttttttient" + SMS.PatientList);
			SMS.getTotalNoPatients();
			//cancel button
			if (listenforClickAddEdit.getSource() == APG.backBut)
			{
				JOptionPane.showMessageDialog(null, "Cancelling and returning to main screen.") ;
				APG.setVisible(false);
				DAMGUI.setVisible(true);
				
			}
			//Clear button
			if (listenforClickAddEdit.getSource() == APG.clearBut)
			{
				int selectedOption = JOptionPane.showConfirmDialog(null, "Are you sure you want to clear all fields?", "Clear confirm", JOptionPane.YES_NO_OPTION);
						
				
				if (selectedOption == JOptionPane.YES_OPTION)
				{
				APG.addressField.setText("");
				APG.dobfield.setText("");
				APG.hisField.setText("");
				APG.patientFirstNameField.setText("");
				APG.PatientNoField.setText("");
				APG.patientSurnameField.setText("");
				APG.patientSurnameField.setText("");
				APG.ppsField.setText("");
				APG.allergies.setText("");
				}
				
			
			}
		 }
	}
	
	public class BackupRestoreListener implements ActionListener
	{
		
	public void actionPerformed(ActionEvent RestoreBackup) 
	    {
			//listenerEvent actions if the restore button is clicked.
			if (RestoreBackup.getSource() == DAMGUI.restore)
			{
			JOptionPane.showConfirmDialog(null, "Are you sure you want to restore data from File?") ;
			SMS.restore();
			}
			
			//Actions to be performed if the the backup button event occurs.Serializing arraylist.
			if (RestoreBackup.getSource() == DAMGUI.backUp)
			{
			JOptionPane.showConfirmDialog(null, "Are you sure you want to Backup data to File?") ;
			SMS.backup();
			}
			if (RestoreBackup.getSource() == DAMGUI.logOut)
			{
			JOptionPane.showConfirmDialog(null, "logging out") ;
			DAMGUI.dispose();
			}
	     }
	}
	
	
	
	public class ClickListener implements MouseListener
	{
		
		@Override
		public void mouseClicked(MouseEvent e) {
			if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1)
			{
				System.out.println("TEST mouse click");
			}
			
		}

		

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}



		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
	}
	}

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;

import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.TitledBorder;
import javax.swing.event.TableModelListener;



public class DocAppMainGUI extends JFrame 

{
	JButton  addNew,updatePatient,searchPatient,restore,logOut,backUp;
	JComboBox searchCriteriaComboBox;
	JTable table;
	DefaultTableModel model;
	JTextArea prevconditionArea, allergyArea,currentProblem, medicationArea;
	
	
	
	public JTable getTable()
	
	{
		return table;
	}
	public void setTable(JTable table) 
	{
		this.table = table;
	}
	
	
	 
	 public DocAppMainGUI()
	 {
	    //Creating  edit panel
    	          JPanel editandSearchOptionsPanel = new JPanel(
                  new FlowLayout(FlowLayout.RIGHT, 3,3));
    	          editandSearchOptionsPanel.setBorder(new TitledBorder("Patient Details") );
                
                
                //Add  Buttons to edit panel(edit,add and search panel)
    	         addNew = new JButton("Add Patient");
                editandSearchOptionsPanel.add( addNew );
               //UPdate Patient Button
                 updatePatient = new JButton("Update Patient");
                editandSearchOptionsPanel.add( updatePatient );
               
               //Search Patient Button
                searchPatient = new JButton("Search Patient");
                editandSearchOptionsPanel.add( searchPatient );
               
              //Declaring gui of type Jpanel
                final JPanel gui =  new JPanel(new BorderLayout(5,5));
                
                
                gui.setBorder( new TitledBorder("DocApp-Main GUI") );
               
                //Declaring options for searching patient
                String searchOptions[] =
                		 { "Name", "DOB", "PPS NO.",   "Condition" };
                
                 searchCriteriaComboBox = new JComboBox( searchOptions );
                editandSearchOptionsPanel.add(searchCriteriaComboBox);
               
                
                final JCheckBox checkbox = new JCheckBox("Edit Patient Details", false);
                editandSearchOptionsPanel.add(checkbox);
                
                //Adding edit panel to the North area of gui
                gui.add(editandSearchOptionsPanel, BorderLayout.NORTH);
                
                //Action listener for patient search
                searchCriteriaComboBox.addActionListener( new ActionListener()
                {
                    public void actionPerformed(ActionEvent ae) 
                    {
                        int index = searchCriteriaComboBox.getSelectedIndex();
                        try {
                        	
                       if (checkbox.isSelected())
                             {
                            	switch (index)
     			               {
     			                   case 0: JOptionPane.showInputDialog( "Enter patients surname and click OK" );     break;
     			                   case 1: JOptionPane.showInputDialog( "Enter patients DOB and click OK" );     break;
     			                   case 2: JOptionPane.showInputDialog( "Enter patients PPS No and click OK" );   break;
     			                   case 3: JOptionPane.showInputDialog( "Enter patients Address and click OK" );      break;
     			                   case 4: JOptionPane.showInputDialog( "Enter patients condition and click OK" );      break;
     			               }
                           }
                        else
                        	JOptionPane.showMessageDialog(null, "Sorting  records by:" );
                        	} 
                        catch(Exception e) 
                        {
                            e.printStackTrace();
                        }
                    }
                } );
                
	 
                //Panel on left side of GUI where user can logout/Backup/restore data
                JPanel logoutPanel = new JPanel(new BorderLayout(14,14));
                
                logoutPanel.setBorder(
                    new TitledBorder("Logout Panel") );
                
                gui.add(logoutPanel, BorderLayout.WEST);

                //Declaring second panel so as to hold the buttons in place on the North of logoutPanel
                JPanel logoutPanel2 = new JPanel(new BorderLayout(14,14));
                
                
                //Declaring buttons which live in the logout panel.
                 logOut = new JButton("Logout");
                logoutPanel2.add( logOut, BorderLayout.NORTH );
               
                backUp = new JButton("Backup");
                logoutPanel2.add( backUp, BorderLayout.CENTER );
                
                restore = new JButton("Restore");
                logoutPanel2.add( restore, BorderLayout.SOUTH );
                
                
                logoutPanel.add(logoutPanel2, BorderLayout.NORTH);

               
             
             //Declaring string for Table content headers.
                
             String[] header = {"Name", "Surname", "Gender" , "Address", "D.O.B","Blood Group", "Phone", " RSI Num"};
          //Adding header and data to model(table) (Initially there will be 0 patients.
             model = new DefaultTableModel(header,0);
             
				
             
             table = new JTable(model);
                try
                	{
                    	// 1.6+
                    	table.setAutoCreateRowSorter(true);
                	} 
                catch(Exception continuewithNoSort)
                {
                	
                }
                
                
                JScrollPane tableScroll = new JScrollPane(table);
                Dimension tablePreferred = tableScroll.getPreferredSize();
                tableScroll.setPreferredSize(
                    new Dimension(tablePreferred.width, tablePreferred.height/3) );
                gui.add( tableScroll, BorderLayout.CENTER );
                
                 
                //Patient History
                //History details etc at end of screen.
               
                
                 JPanel historyPanel = new JPanel(new GridLayout(2,3));
                 historyPanel.setBorder(
                    new TitledBorder("Patient History") );
               
                prevconditionArea = new JTextArea();
                prevconditionArea.setBorder(
                        new TitledBorder(null,"Previous Conditions", TitledBorder.ABOVE_TOP, TitledBorder.TOP, new Font("times new roman",Font.PLAIN,16), Color.BLUE));
                
                prevconditionArea.setEditable(true);
                prevconditionArea.setLineWrap(true);
                prevconditionArea.setWrapStyleWord(true);
                
                
                
                // We create the ScrollPane and instantiate it with the TextArea as an argument
                // along with two constants that define the behaviour of the scrollbars.
                JScrollPane previousDiagnosisArea = new JScrollPane(prevconditionArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                
                // We then set the preferred size of the scrollpane.
                previousDiagnosisArea.setPreferredSize(new Dimension(250, 150));
             // and add it to the GUI.
                historyPanel.add(previousDiagnosisArea);
               
                allergyArea = new JTextArea(); 
                allergyArea.setBorder(
                        new TitledBorder(null, "Allergies", TitledBorder.ABOVE_TOP, TitledBorder.TOP, new Font("times new roman",Font.PLAIN,16), Color.BLUE));
               JScrollPane KnownAllergyArea = new JScrollPane(allergyArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                historyPanel.add(allergyArea);
                KnownAllergyArea.setPreferredSize(new Dimension(250, 150));
                        
                
                currentProblem = new JTextArea(); 
                currentProblem.setBorder(
                        new TitledBorder(null,"Current problem", TitledBorder.ABOVE_TOP, TitledBorder.TOP, new Font("times new roman",Font.PLAIN,16), Color.BLUE));
                JScrollPane CurrentProbArea = new JScrollPane(currentProblem, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                        historyPanel.add(CurrentProbArea);
                        CurrentProbArea.setPreferredSize(new Dimension(250, 150));
                        
                      
                        
                    //Area for Meds    
                        String Medications = "Patient was prescribed Morphine on 22-FEB 13";
                         medicationArea = new JTextArea(Medications); 
                        
                        medicationArea.setBorder(
                                new TitledBorder(null,"Meds Prescribed", TitledBorder.ABOVE_TOP, TitledBorder.TOP, new Font("times new roman",Font.PLAIN,16), Color.BLUE));
                        JScrollPane medicationscrollArea = new JScrollPane(medicationArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                historyPanel.add(medicationscrollArea);
                                medicationscrollArea.setPreferredSize(new Dimension(250, 150));    
                        
                                
                //creating a split frame for history components(historypanel) and adding it underneath the tablescroll
                 JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,tableScroll,
                              new JScrollPane(historyPanel));
                            gui.add( splitPane, BorderLayout.CENTER );

                this.setContentPane(gui);
                this.pack(); /* window to be sized to fit the preferred size of its sub components */
              
                // place window in center of screen 
                this.setLocationRelativeTo(null);
                try {
                    // 1.6+
                	
                    this.setLocationByPlatform(true);
                    this.setMinimumSize(this.getSize());
                } 
                catch(Throwable ignoreAndContinue) 
                {
                }

               
               
            }
	 public void createAndShowDocAppMainGUI() 
   	 {
	this.setTitle("DocApp");
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.pack();
    this.setVisible(true);
    }
	 
	 
	 
	 //Adding listeners for the table data.
	 void rowClickListener(MouseListener listenForMouseClickonRow)
	 {
		 System.out.println("TEST test test");
		 table.addMouseListener( listenForMouseClickonRow);
		 
		 //table.getModel().addTableModelListener(listenForMouseClickonRow);
	 }
	 
	 //Adding listeners for the add/update/etc buttons on Panel on North.
	 void addPatientListener (ActionListener listenForAddorDelClick)
     
     {
		 
		addNew.addActionListener(listenForAddorDelClick);
     	updatePatient.addActionListener(listenForAddorDelClick);
     	searchPatient.addActionListener(listenForAddorDelClick);
     	searchCriteriaComboBox.addActionListener(listenForAddorDelClick);
     	
    } 
	 
	 //Adding listeners for the backup/restore/logout buttons on Panel on west.
 void BackupListener (ActionListener listenForBackupRestore)
     
     {
     	restore.addActionListener(listenForBackupRestore);
     	logOut.addActionListener(listenForBackupRestore);
     	backUp.addActionListener(listenForBackupRestore);
     	
     } 
    
 
 
}

public class SurgeryMgtSys 
{
	ArrayList<Patient>  PatientList = new ArrayList <Patient>();
	ArrayList<PatientHistory> HistoryList = new ArrayList<PatientHistory>();

	
	
SurgeryMgtSys()
	{
	
	
	}

//Method for adding Patient to arraylist
public void addPatient(Patient p) 

	{
	
	//adding patient and patient detail to the patient list arraylist
	PatientList.add(p);
	this.printPatientArrayListDetToConsole(PatientList);
	
	} 


public void addPatienthistory(PatientHistory ph) 

{

//adding patients history details to the PatientHistory arraylist.
	HistoryList.add(ph);

} 

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2