View Single Post
  #2 (permalink)  
Old 08-01-2007, 08:45 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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(); } }
Reply With Quote