Results 1 to 2 of 2
  1. #1
    coco is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default Help with algorithm in java

    Hi, I need to submit this program in a few hours.
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    
    public class PatientDetails extends JFrame implements ActionListener
    {
    JFrame frame;
    JPanel panel;
    JLabel patientFirstName;
    JLabel patientMiddleName;
    JLabel patientLastName;
    JLabel patientPhoneNumber;
    JLabel patientPostalAddress;
    JTextField textPatientFirstName;
    JTextField textPatientMiddleName;
    JTextField textPatientLastName;
    JTextField textPatientPhoneNumber;
    JTextField textPatientPostalAddress;
    JComboBox patientChoice;
    JList paymentOption;
    JButton button;
    
    public static void main (String args[])
    {
     frame = new JFrame ("PatientDetails");
     panel = new JPanel ();
     frame.getContentPane().add(panel);
     panel.setLayout (new FlowLayout ());
     
     patientFirstName = new JLabel ("First Name: ");
     textPatientFirstName = new JTextField (15);
     
     patientMiddleName = new JLabel ("Middle Name: ");
     textPatientMiddleName = new JTextField (15);
     
     patientLastName = new JLabel ("Last Name: ");
     textPatientLastName = new JTextField (15);
     
     patientPhoneNumber = new JLabel ("Phone Number: ");
     textPatientPhoneNumber = new JTextField (15);
     
     patientPostalAddress = new JLabel ("Address: ");
     textPatientPostalAddress = new JTextField (50);
     
     String listOfPaymentOptions [] = {"Credit Card", "Cash", "Check"};
     paymentOption = new JList (listOfPaymentOptions);
     
     String memberChoice [] = {"New Patient", "Regular Patient", "Guest Patient"};
     patientChoice = new JComboBox (memberchoice);
     
     button = new JButton ("Submit");
     
     panel.add(patientFirstName);
     panel.add(textPatientFirstName);
     panel.add(patientMiddleName);
     panel.add(textPatientMiddleName);
     panel.add(patientLastName);
     panel.add(textPatientLastName);
     panel.add(patientPhoneNumber);
     panel.add(textPatientPhoneNumber);
     panel.add(patientPostalAddress);
     panel.add(textPatientPostalAddress);
     panel.add(paymentOption);
     panel.add(patientChoice);
     panel.add(button);
    }
    public class PatientDetails (ActionEvent addingInfo)
    {
     Object abc = addingInfo.getSource ();
     if (abc == button)
     {
      String entry = textPatientFirstName.getText () + ":" + textPatientMiddleName.getText () + ":" + textLastName.getText () + ":" + new String
      (textPatientPhoneNumber.getText()) + ":" + new String (textPatientPostalAddress.getText());
      try
      {
       RandomAccessFile patientFile = new RandomAccessFile ("C:\\Documents and Settings\\Ryan\\My Documents\\File.txt", "rw");
       patientFile.seek(patientFile.length());
       patientFile.writeBytes (entry);
      }
      catch (IOException error)
      {
       showStatus ("Cannot write to file" +error);
      }
     }
    }
    }
    If someone can please tell me what is wrong with this and how I can fix it. I'm only encountering 2 errors which I can't seem to fix.
    Thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    10

    Default

    You had the constructor code inside the main method and the actionPerformed method, required for the enclosing class implementing the ActionListener interface, was crossed up with the constructor signature: public class PatientDetails (ActionEvent addingInfo).
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    
    public class PD extends JFrame implements ActionListener
    {
        // This class extends JFrame so it is a JFrame
        // and you don't need to create a new instance.
    //    JFrame frame;
        JPanel panel;
        JLabel patientFirstName;
        JLabel patientMiddleName;
        JLabel patientLastName;
        JLabel patientPhoneNumber;
        JLabel patientPostalAddress;
        JTextField textPatientFirstName;
        JTextField textPatientMiddleName;
        JTextField textPatientLastName;
        JTextField textPatientPhoneNumber;
        JTextField textPatientPostalAddress;
        JComboBox patientChoice;
        JList paymentOption;
        JButton button;
    
        public PD()
        {
            super("PatientDetails");
            panel = new JPanel (new GridLayout(0,1));
            getContentPane().add(panel);
    //        panel.setLayout (new FlowLayout ());
     
            patientFirstName = new JLabel ("First Name: ");
            textPatientFirstName = new JTextField (15);
     
            patientMiddleName = new JLabel ("Middle Name: ");
            textPatientMiddleName = new JTextField (15);
     
            patientLastName = new JLabel ("Last Name: ");
            textPatientLastName = new JTextField (15);
     
            patientPhoneNumber = new JLabel ("Phone Number: ");
            textPatientPhoneNumber = new JTextField (15);
     
            patientPostalAddress = new JLabel ("Address: ");
            textPatientPostalAddress = new JTextField (50);
     
            String listOfPaymentOptions [] = {"Credit Card", "Cash", "Check"};
            paymentOption = new JList (listOfPaymentOptions);
     
            String memberChoice [] = {"New Patient", "Regular Patient", "Guest Patient"};
            patientChoice = new JComboBox (memberChoice);
     
            button = new JButton ("Submit");
     
            JPanel row1 = new JPanel();
            row1.add(patientFirstName);
            row1.add(textPatientFirstName);
            row1.add(patientMiddleName);
            row1.add(textPatientMiddleName);
            row1.add(patientLastName);
            row1.add(textPatientLastName);
            panel.add(row1);
    
            JPanel row2 = new JPanel();
            row2.add(patientPhoneNumber);
            row2.add(textPatientPhoneNumber);
            panel.add(row2);
    
            JPanel row3 = new JPanel();
            row3.add(patientPostalAddress);
            row3.add(textPatientPostalAddress);
            panel.add(row3);
    
            JPanel row4 = new JPanel();
            row4.add(paymentOption);
            row4.add(patientChoice);
            row4.add(button);
            panel.add(row4);
    
            // JFrame methods
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            pack();
            setLocation(10,200);
            setVisible(true);
        }
    
        public void actionPerformed(ActionEvent addingInfo)
        {
            Object abc = addingInfo.getSource ();
            if (abc == button)
            {
                String entry = textPatientFirstName.getText () + ":" +
                               textPatientMiddleName.getText () + ":" +
                               textPatientLastName.getText () + ":" +
                               new String(textPatientPhoneNumber.getText()) + ":" +
                               new String(textPatientPostalAddress.getText());
                try
                {
                    RandomAccessFile patientFile =
                        new RandomAccessFile ("C:\\Documents and Settings\\Ryan\\" +
                                              "My Documents\\File.txt", "rw");
                    patientFile.seek(patientFile.length());
                    patientFile.writeBytes (entry);
                }
                catch (IOException error)
                {
                    System.out.println("Cannot write to file" +error);
                }
            }
        }
    
        public static void main (String args[])
        {
            new PD();
        }
    }

Similar Threads

  1. Soundex Algorithm Implementation in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:40 PM
  2. Using Java To Implement RSA Algorithm
    By Floetic in forum New To Java
    Replies: 3
    Last Post: 03-31-2008, 11:56 PM
  3. Help with algorithm
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 10:26 PM
  4. Help me with this algorithm
    By Marcus in forum Advanced Java
    Replies: 3
    Last Post: 07-02-2007, 01:30 PM
  5. Help with Algorithm
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •