import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class FinalAssignment extends JFrame implements ActionListener
{
FlowLayout flow = new FlowLayout();
private JLabel headTitle = new JLabel("Passenger List");
private Font headFont = new Font ("Courier", Font.ITALIC, 18);
private JLabel enterName = new JLabel ("Enter the passenger's Full Name");
private JTextField inputName = new JTextField(10);
private JLabel address = new JLabel("Address");
private JTextField inputAddress = new JTextField(15);
private JButton enterData = new JButton("Enter Data");
int section, seats[], asile;
int window, people;
private JLabel win = new JLabel ("Press 1 for Window seat");
private JLabel asi = new JLabel ("Press 2 for Asile");
private JButton yButton = new JButton ("Yes");
private JButton nButton = new JButton ("No");
private JTextField input = new JTextField(5);
private Container con = getContentPane();
DataOutputStream outStream;
public static void main(String[] args)
{
FinalAssignment fAssign = new FinalAssignment();
fAssign.setSize(600, 220);
fAssign.setVisible(true);
}
String[] airlines = {"Jet Blue", "Delta", "American"};
JComboBox airLines = new JComboBox(airlines);
JLabel mainLabel = new JLabel("Please Select your Airline:");
JLabel actionLabel = new JLabel("Selected Airline: None");
FinalAssignment fA = new FinalAssignment();
public FinalAssignment()
{
super("Victor E. Campudoni-Final-Assignment");
try
{
outStream = new DataOutputStream(new FileOutputStream("PassList.dat"));
}
catch(IOException ex)
{
System.err.println("File not opened");
System.exit(1);
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
headTitle.setFont(headFont);
mainLabel.setFont(headFont);
con.setLayout(flow);
con.add(mainLabel);
con.add(airLines);
con.add(actionLabel);
con.add(headTitle);
con.add(enterName);
con.add(inputName);
con.add(address);
con.add(inputAddress);
con.add(enterData);
con.add(win);
con.add(asi);
con.add(input);
con.add(yButton);
con.add(nButton);
airLines.addActionListener(this);
enterData.addActionListener(this);
yButton.addActionListener(this);
nButton.addActionListener(this);
setVisible(true);
yButton.setEnabled(true);
nButton.setEnabled(true);
seats = new int[11];
asile = 6;
window = 1;
}
public void actionPerformed (ActionEvent e1)
{
int i = airLines.getSelectedIndex();
if(i < 0)
return;
actionLabel.setText("Your AirLine is: " + airLines.getItemAt(i));
{
if (e.getSource() == input && people <= 10)
{
section = Integer.parseInt(input.getText());
String s = "";
if (section == 1)
{
if (window <= 10 && seats [window] == 0)
{
s = "Window. Seat #" + window;
seats [window++] = 1;
people++;
}
else if (window > 10 && asile <= 5)
{
yButton.setEnabled(true);
nButton.setEnabled(true);
s = "Window is full. Asile seat?";
}
else
s = "Your flight leaves in 3 hours.";
}
else if (section == 2)
{
if (seats [asile] == 0 && asile <= 5)
{
s = "Asile. Seat #" + asile;
seats [asile++] = 1;
people++;
}
else if (asile > 5 && window <= 10)
{
yButton.setEnabled(true);
nButton.setEnabled(true);
s = "Asile seating is full. Window Seat?";
}
else
s = "Your flight leaves in 3 hours.";
}
else
s = "Invalid Input.";
System.out.println(s);
}
else if (e.getSource() == yButton)
{
if (section == 1)
{
System.out.println("Your seat assignment is " + window);
seats [window++] = 1;
}
++people;
nButton.setEnabled(true);
yButton.setEnabled(true);
}
else if (e.getSource() == nButton)
{
System.out.println("Your flight leaves in 3 hours.");
nButton.setEnabled(true);
yButton.setEnabled(true);
}
try
{
outStream.writeUTF(inputName.getText());
outStream.writeUTF(inputAddress.getText());
inputName.setText("");
inputAddress.setText("");
}
catch(IOException e2)
{
System.err.println("Error writing file");
System.exit(1);
}
}
}
}