| |2yan |
Nov 29th, 2004 6:27 AM |
Hi guys. I'm new to this forum. I needed to create a project for my class and it should be either an applet or an application that has fields where a user can enter details and store them in a file. I have created this program, but I'm encountering a few problems. Can you guys please help, I need to submit this tomorrow. Here it is:
:
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);
}
}
}
}
Any suggestions, can you guys compile it and find out what's wrong. thanks for reading this. By the way, I'm just learning java so if I'm messing up, please tell me where and why.
ryan
|