Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package window.views;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.Font;
- import java.awt.Image;
- import javax.swing.JTextField;
- import javax.swing.JComboBox;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.Color;
- import javax.swing.JScrollPane;
- import com.toedter.calendar.JDateChooser;
- import javax.swing.JTextArea;
- import javax.swing.DefaultComboBoxModel;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import java.beans.PropertyChangeListener;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.beans.PropertyChangeEvent;
- public class Receptionist_EditPatients extends JFrame {
- private JPanel contentPane;
- private JTextField txtPatient_ID;
- private JTextField txtName;
- private JTextField txtAge;
- private JTextField txtContact;
- private JLabel lblPatient_IDValid;
- private JLabel lblNameValid;
- private JLabel lblDateOfBirthValid;
- private JLabel lblAgeValid;
- private JLabel lblContactValid;
- private JLabel lblAddressValid;
- private JTextArea taAddress;
- private JDateChooser dateChooser;
- private JLabel lblBackground;
- private JButton btnSearch;
- ArrayList<Patient>patientList = new ArrayList<Patient>();
- private JComboBox cbGender;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Receptionist_EditPatients frame = new Receptionist_EditPatients();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Receptionist_EditPatients() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 922, 604);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- //To read all the data out from the User text
- try {
- Scanner sc = new Scanner(new FileReader("patient.txt"));
- while(sc.hasNextLine()) {
- String[] patientDetails = sc.nextLine().split(",");
- if (patientDetails.length < 7) //ill-formed record - should not occur
- continue;
- int patient_id = Integer.parseInt(patientDetails[0].trim()) ;
- int patient_age = Integer.parseInt(patientDetails[1].trim());
- int patient_contact = Integer.parseInt(patientDetails[2].trim());
- String patient_name = patientDetails[3].trim();
- String patient_address = patientDetails[4].trim();
- String patient_dob = patientDetails[5].trim() ;
- String patient_gender = patientDetails[6].trim();
- // (JTextField)dateChooser.getDateEditor().getUiComponent()).getText( patientDetails[5].trim())
- Patient patient = new Patient(patient_id,patient_age,patient_contact,patient_name,patient_address,patient_dob,patient_gender);
- patientList.add(patient);
- //Any newly assigned customer numbers will be distinct from these
- }
- }catch(IOException ex) {
- System.err.println("Warning: could not read Patient file");
- }
- System.out.print(patientList);
- JLabel lblPleaseEditthePatient = new JLabel("Please Edit the Patient Details");
- lblPleaseEditthePatient.setBounds(62, 15, 283, 26);
- lblPleaseEditthePatient.setFont(new Font("Dialog", Font.PLAIN, 20));
- JLabel label_1 = new JLabel("Contact");
- label_1.setFont(new Font("Tahoma", Font.PLAIN, 13));
- label_1.setBounds(485, 199, 59, 13);
- JButton btnBack = new JButton("Back");
- btnBack.setBackground(new Color(75, 122, 242));
- btnBack.setForeground(new Color(255, 255, 255));
- Image imageback = new ImageIcon(this.getClass().getResource("/back.png")).getImage();
- btnBack.setIcon(new ImageIcon(imageback));
- btnBack.setBounds(323, 438, 102, 52);
- btnBack.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- //Create a new JFrame
- Receptionist_ManagePatients receptionist_addmanageAppointments = new Receptionist_ManagePatients();
- receptionist_addmanageAppointments.setVisible(true);
- //Close The Current JFrame
- Receptionist_EditPatients.this.dispose();
- Receptionist_EditPatients.this.setVisible(false);
- }
- });
- JButton btnSubmit = new JButton("Submit");
- btnSubmit.setBackground(new Color(59, 226, 61));
- btnSubmit.setForeground(new Color(255, 255, 255));
- Image imagesubmit = new ImageIcon(this.getClass().getResource("/submit.png")).getImage();
- btnSubmit.setIcon(new ImageIcon(imagesubmit));
- btnSubmit.setBounds(500, 438, 114, 52);
- btnSubmit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- validAddPatients();
- }
- });
- JLabel label_2 = new JLabel("Date Of Birth");
- label_2.setBounds(62, 133, 124, 32);
- label_2.setFont(new Font("Tahoma", Font.PLAIN, 13));
- JLabel label_3 = new JLabel("Address ");
- label_3.setBounds(62, 265, 50, 16);
- label_3.setFont(new Font("Tahoma", Font.PLAIN, 13));
- JLabel label_4 = new JLabel("Name");
- label_4.setBounds(486, 78, 66, 16);
- label_4.setFont(new Font("Tahoma", Font.PLAIN, 13));
- JLabel label_5 = new JLabel("Age");
- label_5.setBounds(486, 134, 33, 16);
- label_5.setFont(new Font("Tahoma", Font.PLAIN, 13));
- JLabel label_6 = new JLabel("Gender");
- label_6.setFont(new Font("Tahoma", Font.PLAIN, 13));
- label_6.setBounds(62, 196, 114, 13);
- JLabel label_7 = new JLabel("Patients_ID");
- label_7.setBounds(62, 85, 97, 16);
- label_7.setFont(new Font("Tahoma", Font.PLAIN, 13));
- cbGender = new JComboBox();
- cbGender.setBounds(192, 193, 218, 20);
- cbGender.setModel(new DefaultComboBoxModel(new String[] {"Male", "Female"}));
- txtPatient_ID = new JTextField();
- txtPatient_ID.setBounds(192, 74, 218, 27);
- txtPatient_ID.addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- Object txt = e.getSource();
- if(txt==txtPatient_ID)
- {
- char ch=e.getKeyChar();
- String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
- String integer="1234567890";
- String character = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" ;
- //txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\\\s*]", " "));
- if (txtPatient_ID.getText().trim().length() == 0 ) {
- lblPatient_IDValid.setText("Cannot Be Empty.");
- txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[\\s+]", ""));
- }
- else if (txtPatient_ID.getText().trim().length() > 12 ) {
- lblPatient_IDValid.setText(" Maximun is 12 Number.");
- txtPatient_ID.getText();
- txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\W]",""));
- if(integer.indexOf(ch)>-1) {
- txtPatient_ID.setText(txtPatient_ID.getText().substring(0, txtPatient_ID.getText ().length() - 1));
- }
- }
- else if (txtPatient_ID.getText().trim().length() <= 12 )
- {
- if (character.indexOf(ch)>-1)
- {
- lblPatient_IDValid.setText(" Chracter is not allowed.");
- txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z]",""));
- }
- else if (specialchar.indexOf(ch)>-1)
- {
- lblPatient_IDValid.setText(" Special Chracter is not allowed.");
- txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("\\W",""));
- }
- else {
- lblPatient_IDValid.setText("");
- }
- }
- else
- {
- txtPatient_ID.setText(txtPatient_ID.getText().substring(0, txtPatient_ID.getText().length()-1));
- lblPatient_IDValid.setText("Maximun is 12 Digit Number.");
- }
- }
- }
- });
- txtPatient_ID.setColumns(10);
- txtName = new JTextField();
- txtName.setEnabled(false);
- txtName.setBounds(571, 74, 210, 27);
- txtName.addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- Object txt = e.getSource();
- if(txt==txtName)
- {
- char ch=e.getKeyChar();
- String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
- String integer="1234567890";
- String character = "QWERTYUIOPASDFGHJKLZXCVBNM" + "qwertyuiopasdfghjklzxcvbnm" ;
- if (txtName.getText().trim().length() == 0 ) {
- lblNameValid.setText("Cannot Be Empty.");
- txtName.setText(txtName.getText().replaceAll("[\\s+]",""));
- }
- else
- {
- if (specialchar.indexOf(ch)>-1 )
- {
- lblNameValid.setText("Special Character is not allow.");
- txtName.setText(txtName.getText().replaceAll("[\\W]",""));
- }
- else if(integer.indexOf(ch)>-1)
- {
- lblNameValid.setText("Integer is not allow.");
- txtName.setText(txtName.getText().replaceAll("[0-9]",""));
- }
- else {
- lblNameValid.setText("");
- }//end inner inner loop else
- }//end inner loop else
- }//end else
- }
- });
- txtName.setColumns(10);
- txtAge = new JTextField();
- txtAge.setEnabled(false);
- txtAge.setBounds(570, 130, 211, 27);
- txtAge.addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- Object txt = e.getSource();
- if(txt==txtAge)
- {
- char ch=e.getKeyChar();
- String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
- String integer="1234567890";
- String character = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" ;
- //txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\\\s*]", " "));
- if (txtAge.getText().trim().length() == 0 ) {
- lblAgeValid.setText("Cannot Be Empty.");
- txtAge.setText(txtAge.getText().replaceAll("[\\s+]", ""));
- }
- else if (txtAge.getText().trim().length() > 3 ) {
- lblAgeValid.setText(" Maximun is 3 Number.");
- txtAge.getText();
- txtAge.setText(txtAge.getText().replaceAll("[A-Za-z\\W]",""));
- if(integer.indexOf(ch)>-1) {
- txtAge.setText(txtAge.getText().substring(0, txtAge.getText ().length() - 1));
- }
- }
- else if (txtAge.getText().trim().length() <= 3 )
- {
- if (character.indexOf(ch)>-1)
- {
- lblAgeValid.setText(" Chracter is not allowed.");
- txtAge.setText(txtAge.getText().replaceAll("[A-Za-z]",""));
- }
- else if (specialchar.indexOf(ch)>-1)
- {
- lblAgeValid.setText(" Special Character is not allowed.");
- txtAge.setText(txtAge.getText().replaceAll("\\W",""));
- }
- else {
- lblAgeValid.setText("");
- }
- }
- else
- {
- txtAge.setText(txtAge.getText().substring(0, txtAge.getText().length()-1));
- lblAgeValid.setText("Maximun is 3 Digit Number.");
- }
- }
- }
- });
- txtAge.setColumns(10);
- lblDateOfBirthValid = new JLabel("");
- lblDateOfBirthValid.setBounds(192, 168, 303, 15);
- lblDateOfBirthValid.setForeground(Color.RED);
- lblNameValid = new JLabel("");
- lblNameValid.setBounds(571, 104, 303, 15);
- lblNameValid.setForeground(Color.RED);
- JScrollPane scrollPane = new JScrollPane();
- scrollPane.setBounds(194, 267, 591, 100);
- lblAddressValid = new JLabel("");
- lblAddressValid.setBounds(194, 351, 301, 16);
- lblAddressValid.setForeground(Color.RED);
- txtContact = new JTextField();
- txtContact.setEnabled(false);
- txtContact.setBounds(570, 192, 211, 27);
- txtContact.addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- Object txt = e.getSource();
- if(txt==txtContact)
- {
- char ch=e.getKeyChar();
- String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
- String integer="1234567890";
- String character = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" ;
- //txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\\\s*]", " "));
- if (txtContact.getText().trim().length() == 0 ) {
- lblContactValid.setText("Cannot Be Empty.");
- txtContact.setText(txtContact.getText().replaceAll("[\\s+]", ""));
- }
- else if (txtContact.getText().trim().length() > 11 ) {
- lblContactValid.setText(" Maximun is 11 Number.");
- txtContact.getText();
- txtContact.setText(txtContact.getText().replaceAll("[A-Za-z\\W]",""));
- if(integer.indexOf(ch)>-1) {
- txtContact.setText(txtContact.getText().substring(0, txtContact.getText ().length() - 1));
- }
- }
- else if (txtContact.getText().trim().length() <= 11 )
- {
- if (character.indexOf(ch)>-1)
- {
- lblContactValid.setText(" Chracter is not allowed.");
- txtContact.setText(txtContact.getText().replaceAll("[A-Za-z]",""));
- }
- else if (specialchar.indexOf(ch)>-1)
- {
- lblContactValid.setText(" Special Character is not allowed.");
- txtContact.setText(txtContact.getText().replaceAll("\\W",""));
- }
- else {
- lblContactValid.setText("");
- }
- }
- else
- {
- txtContact.setText(txtContact.getText().substring(0, txtContact.getText().length()-1));
- lblContactValid.setText("Maximun is 12 Digit Number.");
- }
- }
- }
- });
- txtContact.setColumns(10);
- lblContactValid = new JLabel("");
- lblContactValid.setBounds(573, 230, 301, 16);
- lblContactValid.setForeground(Color.RED);
- lblAgeValid = new JLabel("");
- lblAgeValid.setBounds(569, 168, 268, 15);
- lblAgeValid.setForeground(Color.RED);
- dateChooser = new JDateChooser();
- dateChooser.getCalendarButton().setEnabled(false);
- dateChooser.setBounds(192, 133, 218, 24);
- dateChooser.setDateFormatString("ddMMMyyyy");
- //disable Editable text field in dateChooser
- ((JTextField)dateChooser.getDateEditor().getUiComponent()).setEditable(false);
- dateChooser.addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- //if date had been choose the it will empty
- if(((JTextField)dateChooser.getDateEditor().getUiComponent()).getText().isEmpty())
- {
- } else {
- lblDateOfBirthValid.setText("");
- }
- }
- });
- dateChooser.getCalendarButton().addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- //if date not been choose the it will get alert message
- if(((JTextField)dateChooser.getDateEditor().getUiComponent()).getText().isEmpty())
- {
- lblDateOfBirthValid.setText("Date should be filled");
- } else {
- lblDateOfBirthValid.setText("");
- }
- }
- });
- lblPatient_IDValid = new JLabel("");
- lblPatient_IDValid.setBounds(192, 107, 234, 16);
- lblPatient_IDValid.setForeground(Color.RED);
- taAddress = new JTextArea();
- taAddress.setEnabled(false);
- taAddress.setTabSize(0);
- taAddress.setLineWrap(true);
- taAddress.setWrapStyleWord(true);
- taAddress.addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- Object txt = e.getSource();
- if(txt==taAddress)
- {
- char ch=e.getKeyChar();
- String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
- String integer="1234567890";
- String character = "QWERTYUIOPASDFGHJKLZXCVBNM" + "qwertyuiopasdfghjklzxcvbnm" ;
- if (taAddress.getText().trim().length() == 0 ) {
- lblAddressValid.setText("Cannot Be Empty.");
- taAddress.setText(taAddress.getText().replaceAll("[\\s+]",""));
- }
- else {
- lblAddressValid.setText("");
- }//end inner inner loop else
- }//end inner loop else
- }//end else
- });
- scrollPane.setViewportView(taAddress);
- contentPane.setLayout(null);
- contentPane.add(lblPleaseEditthePatient);
- contentPane.add(label_7);
- contentPane.add(txtPatient_ID);
- contentPane.add(lblPatient_IDValid);
- contentPane.add(label_4);
- contentPane.add(txtName);
- contentPane.add(lblNameValid);
- contentPane.add(label_2);
- contentPane.add(dateChooser);
- contentPane.add(lblDateOfBirthValid);
- contentPane.add(label_5);
- contentPane.add(txtAge);
- contentPane.add(lblAgeValid);
- contentPane.add(label_1);
- contentPane.add(txtContact);
- contentPane.add(lblContactValid);
- contentPane.add(label_3);
- contentPane.add(scrollPane);
- contentPane.add(lblAddressValid);
- contentPane.add(label_6);
- contentPane.add(btnBack);
- contentPane.add(cbGender);
- contentPane.add(btnSubmit);
- Image imagelogout = new ImageIcon(this.getClass().getResource("/backgroundImage.png")).getImage();
- btnSearch = new JButton("Search");
- btnSearch.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- int patient_ID = Integer.parseInt(txtPatient_ID.getText());
- for(int i = 0; i <patientList.size() ; i ++) {
- if(patientList.get(i).getPatient_ID() == patient_ID) {
- /*(int patient_ID, String appointmen_ID, String doctor_ID, String dateAndTime, String hour,
- String minutes, String typeOfCustomer, String specialNotes) {
- */
- txtAge.setText("" + patientList.get(i).getAge());
- txtContact.setText("" + patientList.get(i).getContact());
- txtName.setText(patientList.get(i).getName());
- taAddress.setText(patientList.get(i).getAddress());
- //dateChooser.setText(patientList.get(i).getAddress());
- cbGender.setSelectedItem((patientList.get(i).getGender()));
- txtPatient_ID.setEnabled(false);
- txtAge.setEnabled(true);
- txtContact.setEnabled(true);
- txtName.setEnabled(true);
- taAddress.setEnabled(true);
- dateChooser.setEnabled(true);
- cbGender.setEnabled(true);
- System.out.println(patientList);
- }//end if
- }//end for
- }
- });
- btnSearch.setBounds(384, 36, 97, 25);
- contentPane.add(btnSearch);
- lblBackground = new JLabel("");
- lblBackground.setIcon(new ImageIcon(imagelogout));
- lblBackground.setBounds(0, 0, 910, 569);
- contentPane.add(lblBackground);
- }
- public void validAddPatients() {
- if(txtPatient_ID.getText().trim().isEmpty()|| txtName.getText().trim().isEmpty() || txtAge.getText().trim().isEmpty() || txtContact.getText().trim().isEmpty()
- || taAddress.getText().trim().isEmpty() || dateChooser.getDate() == null ) {
- if(txtPatient_ID.getText().trim().isEmpty() ) {
- lblPatient_IDValid.setText("Please Enter your Staff_ID.");
- }
- if(txtName.getText().trim().isEmpty() ) {
- lblNameValid.setText("Please Enter your Name.");
- }
- if(txtAge.getText().trim().isEmpty() ) {
- lblAgeValid.setText("Please Enter your Age.");
- }
- if(txtContact.getText().trim().isEmpty() ) {
- lblContactValid.setText("Please Enter your Contact.");
- }
- if(taAddress.getText().trim().isEmpty() ) {
- lblAddressValid.setText("Please Enter your Address.");
- }
- if(dateChooser.getDate() == null ) {
- lblDateOfBirthValid.setText("Please Choose you Date of Birth.");
- }
- }
- else {
- //write file here
- int patient_id = Integer.parseInt(txtPatient_ID.getText()) ;
- int patient_age = Integer.parseInt(txtAge.getText());
- int patient_contact = Integer.parseInt(txtContact.getText());
- String patient_name = txtName.getText();
- String patient_address = taAddress.getText();
- //------------convertDate to the 11Mar2019 format--------------
- SimpleDateFormat dFormat = new SimpleDateFormat("ddMMMyyyy");
- String patient_dob = dFormat.format(dateChooser.getDate());
- //---------------------------------------------------------------
- String patient_gender = cbGender.getSelectedItem().toString();
- for(int i = 0; i <patientList.size() ; i ++) {
- if(patientList.get(i).getPatient_ID() == (patient_id)) {
- patientList.get(i).setAge(patient_age);
- patientList.get(i).setContact(patient_contact);
- patientList.get(i).setName(patient_name);
- patientList.get(i).setAddress(patient_address);
- patientList.get(i).setDate_Of_Birth(patient_dob);
- patientList.get(i).setGender(patient_gender);
- }//end if
- }//end for
- try {
- PrintWriter pw = new PrintWriter(new FileWriter("patient.txt"));
- for (int i=0; i<patientList.size(); i++)
- //if (userList.get(i) != null)
- pw.println(patientList.get(i).toString());
- pw.close();
- System.err.println("Patient saved!");
- JOptionPane.showMessageDialog(null, "The Patient Details is Sucessfully Added.");
- }
- catch (IOException ex) {
- System.err.println("Error! : Could not save patient.");
- }
- txtPatient_ID.setText("");
- txtAge.setText("");
- txtContact.setText("");
- txtName.setText("");
- taAddress.setText("");
- dateChooser.setDate(null);
- taAddress.setText("");
- txtPatient_ID.setEnabled(true);
- txtAge.setEnabled(false);
- txtContact.setEnabled(false);
- txtName.setEnabled(false);
- taAddress.setEnabled(false);
- dateChooser.setEnabled(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement