Here is my coding. I'm trying to have it open and collect data for two different files (Grad Student and Undergrad Student). Right now, I just can't get it to compile. PLEASE help me correct this.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CreateStudentFiles extends JFrame
implements ActionListener
{
private JLabel title =
new JLabel ("Create Student Files");
private Font bigFont = new Font ("Arial", Font.BOLD, 24);
private JLabel prompt =
new JLabel ("Enter student data, then select one button:");
private JTextField idField = new JTextField (5);
private JTextField lastNameField = new JTextField (10);
private JTextField firstNameField = new JTextField (10);
private JLabel idLabel = new JLabel ("ID number");
private JLabel lastNameLabel = new JLabel ("Last Name");
private JLabel firstNameLabel = new JLabel ("First Name");
private JButton gradStudentButton =
new JButton ("Grad student");
private JButton undergradStudentButton =
new JButton ("Undergrad student");
private Container con = getContentPane ();
DataOutputStream ostream;
public CreateStudentFiles ()
{
super ("Create Student Files");
try
{
ostream = new DataOutputStream
(new FileOutputStream ("StuData.dat"));
}
catch (IOException e)
{
System.err.println ("File not opened");
System.exit (1);
}
con.setLayout (new FlowLayout ());
title.setFont (bigFont);
con.add (title);
con.add (prompt);
con.add (idLabel);
con.add (idField);
con.add (lastNameLabel);
con.add (lastNameField);
con.add (firstNameLabel);
con.add (firstNameField);
con.add (gradStudentButton);
con.add (undergradStudentButton);
gradStudentButton.addActionListener (this);
undergradStudentButton.addActionListener (this);
setSize (320, 200);
setVisible (true);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e1)
{
int idNumber;
try
{
idNumber = Integer.parseInt (idNumber.getText());
ostream.writeUTF (lastName.getText());
ostream.writeUTF (firstName.getText());
ostream.writeInt (idNumber);
lastName.setText ("");
firstName.setText ("");
idNumber.setText ("");
}
catch (NumberFormatException e2)
{
System.err.println("Invalid ID number");
}
catch (IOException e3)
{
System.err.println("Error writing file");
System.exit(1);
}
}
public static void main (String[] args)
{
CreateStudentFiles csf = new CreateStudentFiles();
}
}
Thanks for your help, this is due by the end of the weekend!
Mariko

New Topic/Question
Reply



MultiQuote








|