This is what it is supposed to do. If this helps.
This file should read the records from the Graduate file first,
in sequential order as the “View Student” button is pressed.
When the program reaches the end of the Graduate Students
records, it should modify the JFrame to display
“Undergraduate Students” and then read and display the
files from the Undergraduate database
I have been working on this for weeks and have not been able to figure out what I must do to achieve this. Any help is appreciated.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.JFrame;
public class StudentRead extends JFrame implements ActionListener
{
private JLabel gradStudentList = new JLabel("GRADUATE Student List",JLabel.CENTER);
private JLabel undergradStudentList = new JLabel("UNDERGRADUATE Student List",JLabel.CENTER);
private Font bigFont = new Font("Arial", Font.ITALIC, 24);
private JLabel prompt = new JLabel("View the students",JLabel.CENTER);
private JTextField idNumText = new JTextField(4);
private JTextField lastNameText = new JTextField(6);
private JTextField firstNameText = new JTextField(6);
private JLabel idNumberLabel = new JLabel("ID Number",JLabel.CENTER);
private JLabel lastNameLabel = new JLabel("Last name",JLabel.RIGHT);
private JLabel firstNameLabel = new JLabel("First name",JLabel.RIGHT);
private JButton viewStudentButton = new JButton("View Student");
private Container con = getContentPane();
DataInputStream gradStudentInStream;
DataInputStream undergradStudentInStream;
public StudentRead()
{
super("Read Student Records");
try
{
gradStudentInStream = new DataInputStream(new FileInputStream("GradStudentsFile"));
undergradStudentInStream = new DataInputStream(new FileInputStream("UndergradStudentsFile"));
}
catch(IOException e)
{
System.err.println("File not opened");
System.exit(1);
}
setSize(300,175);
con.setLayout(new FlowLayout());
gradStudentList.setFont(bigFont);
con.add(gradStudentList);
con.add(prompt);
con.add(idNumberLabel);
con.add(idNumText);
con.add(lastNameLabel);
con.add(lastNameText);
con.add(firstNameLabel);
con.add(firstNameText);
con.add(viewStudentButton);
viewStudentButton.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
String lastName, firstName;
int IdNum;
try
{
IdNum = gradStudentInStream.readInt();
lastName = gradStudentInStream.readUTF();
firstName = gradStudentInStream.readUTF();
idNumText.setText(String.valueOf(IdNum));
lastNameText.setText(lastName);
firstNameText.setText(firstName);
}
catch(EOFException e2)
{
closeFile();
System.exit(0);
}
catch(IOException e3)
{
System.err.println("Error reading file");
System.out.println("out");
System.exit(1);
}
}
public void closeFile()
{
try
{
gradStudentInStream.close();
System.exit(0);
}
catch(IOException e)
{
System.err.println("Error closing file");
System.exit(1);
}
}
public static void main(String[] args)
{
StudentRead rsr = new StudentRead();
}
}