Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-01-2007, 07:09 AM
Member
 
Join Date: Jul 2007
Posts: 39
Rep Power: 0
coco is on a distinguished road
Default Help with algorithm in java
Hi, I need to submit this program in a few hours.
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-01-2007, 07:45 AM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
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).
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();
    }
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Soundex Algorithm Implementation in Java Java Tip java.lang 0 04-12-2008 09:40 PM
Using Java To Implement RSA Algorithm Floetic New To Java 3 04-01-2008 12:56 AM
Help with algorithm susan New To Java 1 07-13-2007 11:26 PM
Help me with this algorithm Marcus Advanced Java 3 07-02-2007 02:30 PM
Help with Algorithm Daniel Advanced Java 2 07-02-2007 06:51 AM


All times are GMT +2. The time now is 10:12 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org