Hi Everyone! THis is my final program :D
Of course it's not done...but I just wanted some feedback...and any ideas on how to fix my GUI XD...Any help is appreciated ^^. BUt please don't copy lol XD I don't want to get accused of cheating here...if giving out this code is a mistake, I'll let the mods decide what to do.
//
// copyright buggytoast
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.border.*;
public class AirBox extends JFrame {
private JComboBox destinationComboBox, mealComboBox, classComboBox, dayComboBox, displayComboBox, editComboBox, mealComboBox1, classComboBox1;
// JTEXT AREAS
private JTextArea customerArea, searchResultArea;
// JTEXTFIELDS
private JTextField FirstNameField, LastNameField, mealField, flightField, deleteField, editField, searchField, searchField1, changeNameField;
// JLABELS
private JLabel FirstNameLabel, LastNameLabel, mealLabel, classLabel, customerLabel, MHSLabel, CMLabel, flightLabel, deleteLabel, editLabel, searchLabel, searchLabel1;
//JBUTTONS
private JButton addButton, saveButton, loadButton, deleteButton, searchButton,
changeLNameButton, newButton, ticketButton;
// SCROLLER
private JScrollPane customerListScrollPane;
//JRADIO BUTTONS
private JRadioButton inputRadio, editRadio, searchRadio;
// BUTTON GROUP
private ButtonGroup displayGroup;
//JPANELS
private JPanel editPanel, mainPanel, searchPanel;
// STRING for JCOMBOBOX
private String meal[] = { "Select Meal Type...", "Vegetarian","Meat","Children's Diet","Elderly Diet" };
private String classS[] = { "Select Class...", "First Class", "Second Class" };
private String editCh[] = { "Choose Data to edit...","Change First Name","Change Last Name","Change Meal Type"};
private String display[] = { "Manifest", "Seating Chart"};
private String destinations[] = { "Select Destination", "Mae Hong Son", "Chiang Mai"};
private String meals[] = { "Select Meal", "Normal", "Vegetarian" };
private String classes[] = { "Select Class", "Normal", "Business" };
private String day[] = { "Select Day...", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday" };
// INITIALIZE ObjectOutputStream and ObjectInputStream
private ObjectOutputStream recordfile;
private ObjectInputStream recordedfile;
// CREATE count and maximum size of array of objects
private String outputManifest, outputSeatingArray, outputTicket;
////////////////
private int count;
private int rowCount;
private int aisleCount;
private int firstClassRowCount;
private int firstClassAisleCount;
private int searchCounter;
final int size = 44;
//create string to display flight number
private String flightNum = "RE-";
//create int records to keep track of total number of records entered
private int records;
/////////////////////
/////////////////////
///////////////////////
// Array of Objects
private PassengerData List[];
// Gui Setup
public AirBox()
{
super( "Airlines Reservation");
// create JTabbed Pane
JTabbedPane tabbedPane = new JTabbedPane();
records = 0;
rowCount = 1;
aisleCount = 0;
firstClassRowCount = 6;
firstClassAisleCount = 0;
List = new PassengerData[ size ];
count = -1;
// set up panel1 and add to JTabbedPane
JLabel label1 = new JLabel( "RESERVATION PANEL", SwingConstants.CENTER );
JPanel panel1 = new JPanel();
panel1.add( label1 );
tabbedPane.addTab( "RESERVING", null, panel1, "FirstPanel");
// Input a Meal Combobox for Meal Selection
mealComboBox = new JComboBox( meals );
panel1.add( mealComboBox );
mealComboBox.setBounds( 200, 200, 170, 20 );
mealComboBox.setSelectedIndex( 0 );
// Input A destination combobox for destination selection
destinationComboBox = new JComboBox( destinations );
panel1.add( destinationComboBox );
destinationComboBox.setBounds( 200, 200, 170, 20 );
destinationComboBox.setSelectedIndex( 0 );
// Input a Class comboBox for class selection
classComboBox = new JComboBox( classes );
panel1.add( classComboBox );
classComboBox.setBounds( 200, 200, 170, 20 );
classComboBox.setSelectedIndex( 0 );
FirstNameLabel = new JLabel( "First Name:" );
panel1.add( FirstNameLabel );
FirstNameLabel.setBounds( 10, 20, 100, 20 );
FirstNameField = new JTextField();
panel1.add( FirstNameField );
FirstNameField.setBounds( 80, 20 , 100, 20);
LastNameLabel = new JLabel( "Last Name:" );
panel1.add( LastNameLabel );
LastNameLabel.setBounds( 10, 50, 100, 20 );
LastNameField = new JTextField();
panel1.add( LastNameField );
LastNameField.setBounds( 80, 50 , 100, 20);
mealLabel = new JLabel( "Meal Type:" );
panel1.add( mealLabel );
mealLabel.setBounds( 10, 80, 100, 20 );
classLabel = new JLabel( "Class:" );
panel1.add( classLabel );
classLabel.setBounds( 10, 110, 100, 20 );
flightLabel = new JLabel( "Flight:" );
panel1.add( flightLabel );
flightLabel.setBounds( 350, 20, 100, 20 );
flightField = new JTextField();
panel1.add( flightField );
flightField.setBounds( 400, 20 , 100, 20);
flightField.setEditable( false );
customerLabel = new JLabel( "Passengers" );
panel1.add( customerLabel );
customerLabel.setBounds( 250, 20, 100, 20 );
customerArea = new JTextArea();
panel1.add( customerArea );
customerArea.setEditable( false );
customerArea.setBounds( 250, 50, 300, 400 );
customerArea.setText( "# Name\t\tMeal\tClass\tSeat \n" );
customerListScrollPane = new JScrollPane( customerArea );
customerListScrollPane.setBounds( 250, 50, 500, 400 );
panel1.add( customerListScrollPane );
addButton = new JButton( "Add..." );
panel1.add( addButton );
addButton.setBounds( 50, 200, 100, 20 );
addButton.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent event ){
addCustomer();
}
}
);
saveButton = new JButton( "Save..." );
panel1.add( saveButton );
saveButton.setBounds( 50, 410, 100, 20 );
saveButton.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent event ){
OpenFile1();
SaveToFile(event);
}
}
);
newButton = new JButton( "New" );
panel1.add( newButton );
newButton.setBounds( 50, 350, 100, 20 );
newButton.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent event ){
if( count == -1 ){
destinationComboBox.setEnabled( true );
}
else{
ClearData();
count = -1;
records = 0;
aisleCount = 0;
rowCount = 1;
firstClassAisleCount = 0;
firstClassRowCount = 1;
}
}
}
);
/////////////////////////PANEL 1 OVER//////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
JLabel label2 = new JLabel( "panel two", SwingConstants.CENTER );
JPanel panel2 = new JPanel();
panel2.add( label2 );
tabbedPane.addTab( "EDITING/DELETING", null, panel2, "SecondPanel");
editPanel = new JPanel();
panel2.add( editPanel );
editPanel.setBounds( 20, 5, 215, 450 );
editPanel.setLayout( null );
editPanel.setBorder( new TitledBorder( "Edit" ) );
loadButton = new JButton( "Load..." );
panel2.add( loadButton );
loadButton.setBounds( 50, 380, 100, 20 );
loadButton.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent event ){
boolean opened = false;
opened = OpenFile();
if(opened)
{
LoadFromFile( event );
count--;
records = count + 1;
dataEditable();
}
}
}
);
deleteLabel = new JLabel( "Input Record Number to Delete" );
panel2.add( deleteLabel );
deleteLabel.setBounds( 10, 320, 200, 20 );
deleteButton = new JButton( "Delete Record" );
panel2.add( deleteButton );
deleteButton.setBounds( 10, 380, 200, 20 );
deleteButton.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent event ){
deleteRecord();
}
}
);
deleteField = new JTextField();
panel2.add( deleteField );
deleteField.setBounds( 50, 350, 100, 20 );
editLabel = new JLabel( "Choose record # to edit" );
panel2.add( editLabel );
editLabel.setBounds( 10, 15, 200, 20 );
editField = new JTextField();
panel2.add( editField );
editField.setBounds( 10, 40, 100, 20 );
inputRadio = new JRadioButton( "Input", true );
panel2.add( inputRadio );
inputRadio.setBounds( 30, 455, 60, 20 );
inputRadio.addItemListener( new SelectedInputRadio() );
editRadio = new JRadioButton( "Edit", false );
panel2.add( editRadio );
editRadio.setBounds( 90, 455, 50, 20 );
editRadio.addItemListener( new SelectedEditRadio() );
searchRadio = new JRadioButton( "Search", false );
panel2.add( searchRadio );
searchRadio.setBounds( 140, 455, 80, 20 );
searchRadio.addItemListener( new SelectedSearchRadio() );
displayGroup = new ButtonGroup();
displayGroup.add( inputRadio );
displayGroup.add( searchRadio );
displayGroup.add( editRadio );
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////
JLabel label3 = new JLabel( "panel three", SwingConstants.CENTER );
JPanel panel3 = new JPanel();
panel3.add( label3 );
tabbedPane.addTab( "CALCULATE TICKET PRICE", null, panel3, "ThirdPanel");
JLabel label4 = new JLabel( "panel four", SwingConstants.CENTER );
JPanel panel4 = new JPanel();
panel4.add( label4 );
tabbedPane.addTab( "Thursday", null, panel4, "FourthPanel");
JLabel label5 = new JLabel( "panel five", SwingConstants.CENTER );
JPanel panel5 = new JPanel();
panel5.add( label5 );
tabbedPane.addTab( "Friday", null, panel5, "FivePanel");
getContentPane().add( tabbedPane );
setSize( 500,400 );
setVisible( true );
}
/////////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////////
public void noDate(){
dayComboBox.setEnabled( false );
newButton.setEnabled( true );
}
public void dataEditable(){
editRadio.setEnabled( true );
searchRadio.setEnabled( true );
deleteButton.setEnabled( true );
deleteField.setEditable( true );
searchButton.setEnabled( true );
searchField.setEditable( true );
searchField1.setEditable( true );
editPanel.setVisible( false );
searchPanel.setVisible( false );
newButton.setEnabled( true );
displayComboBox.setEnabled( true );
}
//method for disabling contents if there is no data
public void noData(){
destinationComboBox.setEnabled( false );
displayComboBox.setEnabled( false );
addButton.setEnabled( false );
saveButton.setEnabled( false );
deleteButton.setEnabled( false );
FirstNameField.setEditable( false );
LastNameField.setEditable( false );
classComboBox.setEnabled( false );
mealComboBox.setEnabled( false );
deleteField.setEditable( false );
searchButton.setEnabled( false );
searchField.setEditable( false );
searchField1.setEditable( false );
ticketButton.setEnabled( false );
searchPanel.setVisible( false );
editPanel.setVisible( false );
newButton.setEnabled( true );
displayComboBox.setEnabled( false );
editRadio.setEnabled( false );
searchRadio.setEnabled( false );
}
public void noData1(){
destinationComboBox.setEnabled( true );
displayComboBox.setEnabled( false );
addButton.setEnabled( false );
saveButton.setEnabled( false );
deleteButton.setEnabled( false );
FirstNameField.setEditable( false );
LastNameField.setEditable( false );
classComboBox.setEnabled( false );
mealComboBox.setEnabled( false );
deleteField.setEditable( false );
searchButton.setEnabled( false );
searchField.setEditable( false );
searchField1.setEditable( false );
ticketButton.setEnabled( false );
searchPanel.setVisible( false );
editPanel.setVisible( false );
newButton.setEnabled( true );
displayComboBox.setEnabled( false );
editRadio.setEnabled( false );
searchRadio.setEnabled( false );
}
//method for selecting day and setting the flight number
public void resetSeatCounters(){
aisleCount = 0;
rowCount = 1;
firstClassAisleCount = 0;
firstClassRowCount = 6;
}
public void FlightDayChanged( ItemEvent event){
if( ( event.getStateChange() == ItemEvent.SELECTED ) &&
dayComboBox.getSelectedIndex() != 0 ){
addButton.setEnabled( true );
saveButton.setEnabled( true );
loadButton.setEnabled( true );
FirstNameField.setEditable( true );
LastNameField.setEditable( true );
classComboBox.setEnabled( true );
mealComboBox.setEnabled( true );
//flightComboBox.setEnabled( true );
if( dayComboBox.getSelectedIndex() == 1 ){
ResetFlightNum();
if ( destinationComboBox.getSelectedIndex() == 1 )
flightNum += "1";
else
flightNum += "2";
flightNum += "MO";
}
if( dayComboBox.getSelectedIndex() == 2 ){
ResetFlightNum();
if ( destinationComboBox.getSelectedIndex() == 1 )
flightNum += "1";
else
flightNum += "2";
flightNum += "TU";
}
if( dayComboBox.getSelectedIndex() == 3 ){
ResetFlightNum();
if ( destinationComboBox.getSelectedIndex() == 1 )
flightNum += "1";
else
flightNum += "2";
flightNum += "WE";
}
if( dayComboBox.getSelectedIndex() == 4 ){
ResetFlightNum();
if ( destinationComboBox.getSelectedIndex() == 1 )
flightNum += "1";
else
flightNum += "2";
flightNum += "TH";
}
if( dayComboBox.getSelectedIndex() == 5 ){
ResetFlightNum();
if ( destinationComboBox.getSelectedIndex() == 1 )
flightNum += "1";
else
flightNum += "2";
flightNum += "FR";
}
}
else
noData1();
}
//method actions of JRadioButtons
public void FlightDestinationChanged( ItemEvent event){
if( ( event.getStateChange() == ItemEvent.SELECTED ) &&
destinationComboBox.getSelectedIndex() != 0 ){
dayComboBox.setEnabled( true );
}
else
noData1();
}
public void EditTypeChanged( ItemEvent event){
try{
if ( editField.getText().equals( "" ) ){
JOptionPane.showMessageDialog( this,
"Please choose a valid record" + " to edit" );
editComboBox.setSelectedIndex( 0 );
}
else if( ( event.getStateChange() == ItemEvent.SELECTED ) &&
editComboBox.getSelectedIndex() != 0 ){
if( editComboBox.getSelectedIndex() == 1 ){
changeNameField.setVisible( true );
changeNameField.setEditable( true );
mealComboBox1.setVisible( false );
}
if( editComboBox.getSelectedIndex() == 2 ){
changeNameField.setVisible( true );
changeNameField.setEditable( true );
mealComboBox1.setVisible( false );
}
if( editComboBox.getSelectedIndex() == 3 ){
changeNameField.setVisible( false );
changeNameField.setEditable( false );
mealComboBox1.setVisible( true );
}
}
}
catch(NumberFormatException numberFormatException)
{
JOptionPane.showMessageDialog( this,
"Please enter record number!", "Input Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
public void DisplayTypeChanged( ItemEvent event ){
if( ( event.getStateChange() == ItemEvent.SELECTED ) ){
if( displayComboBox.getSelectedIndex() == 0 ){
displayManifest();
}
if( displayComboBox.getSelectedIndex() == 1 ){
displaySeatingChart();
}
}
}
public void editData(){
if( editComboBox.getSelectedIndex() == 1 ){
editName();
}
if( editComboBox.getSelectedIndex() == 2 ){
editLName();
}
if( editComboBox.getSelectedIndex() == 3 ){
editMeal();
}
}
//method for adding customer to array List and displaying information
private class SelectedInputRadio implements ItemListener{
public void itemStateChanged( ItemEvent e){
mainPanel.setVisible( true );
editPanel.setVisible( false );
searchPanel.setVisible(false);
}
}
private class SelectedEditRadio implements ItemListener{
public void itemStateChanged( ItemEvent e){
mainPanel.setVisible( false );
searchPanel.setVisible( false );
editPanel.setVisible( true );
}
}
private class SelectedSearchRadio implements ItemListener{
public void itemStateChanged( ItemEvent e){
mainPanel.setVisible( false );
editPanel.setVisible(false);
searchPanel.setVisible( true );
}
}
public void addCustomer(){
if( count < size - 1 ){
String name = FirstNameField.getText();
String lname = LastNameField.getText();
String mealT = meal[ mealComboBox.getSelectedIndex() ];
String classt = classS[ classComboBox.getSelectedIndex() ];
String seatChosen = returnSeat( classComboBox.getSelectedIndex() );
//check if data has been entered
if ( name.equals( "" ) || lname.equals( "" ) || mealComboBox.getSelectedIndex() == 0
|| classComboBox.getSelectedIndex() == 0 ){
JOptionPane.showMessageDialog( null, "Please enter in all of" +
" the information for this passenger" );
resetSeatCounters();
}
else if( seatChosen.equals( "" ) )
JOptionPane.showMessageDialog( null, "Class Full" );
else{
count++;
List[ count ] = new PassengerData( name, lname, mealT, seatChosen, classt, flightNum, 1 );
records++;
FirstNameField.setText( "" );
LastNameField.setText( "" );
//create string for display
outputManifest = ( count + 1 ) + ". " + List[ count ].getLastName() +
", " + List[ count ].getFirstName() + "\t\t" + List[ count ].getMealType() + "\t" + classt +
"\t" + List[ count ].getSeat() + "\n";
FirstNameField.requestFocusInWindow();
customerArea.append( outputManifest );//display string output
dataEditable();
}
//create error message if plane is full
if( count == ( size - 1 ) ){
JOptionPane.showMessageDialog( null, "The plane is full" );
FirstNameField.setEditable( false );
LastNameField.setEditable( false );
mealComboBox.setEnabled( false );
classComboBox.setEnabled( false );
addButton.setEnabled( false );
saveButton.setEnabled( true );
}
mealComboBox.setSelectedIndex( 0 );
classComboBox.setSelectedIndex( 0 );
flightField.setText( flightNum );
dayComboBox.setEnabled( false );
destinationComboBox.setEnabled( false );
saveButton.setEnabled( true );
}
}
//method for initializing string flightNum
public void ResetFlightNum(){
flightNum = "RE-";
}
public String returnSeat( int classC ){
String seatReturn;
int aisle = 0;
int row = 0;
if( classC == 1 ){
aisleCount++;
if( aisleCount == 5 ){
rowCount++;
aisleCount = 1;
if( rowCount == 6 ){
rowCount = 12;
}
}
aisle = aisleCount;
row = rowCount;
}
else if( classC == 2){
firstClassAisleCount++;
if( firstClassAisleCount == 5 ){
firstClassRowCount++;
firstClassAisleCount = 1;
if( firstClassRowCount == 12 ){
rowCount = 13;
}
}
aisle = firstClassAisleCount;
row = firstClassRowCount;
}
if( row == 12 || row == 13 ){
seatReturn = "";
}
else{
seatReturn = "Row: " + row + " Seat: " + aisle;
}
return seatReturn;
}
//method for opening files for loading List
public boolean OpenFile(){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
int result = fileChooser.showOpenDialog( this );
if ( result == JFileChooser.CANCEL_OPTION )
return false;
File fileName = fileChooser.getSelectedFile();
//display error messages if any errors occur while loading the file
if ( fileName == null || fileName.getName().equals( "" ) )
JOptionPane.showMessageDialog( this, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE );
else{
try{
recordedfile = new ObjectInputStream( new FileInputStream( fileName ) );
return true;
}
catch ( IOException ioException ) {
JOptionPane.showMessageDialog( this, "Error Opening File",
"Error", JOptionPane.ERROR_MESSAGE );
}
}
return true;
}
//method for opening the file for saving list
public void OpenFile1(){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
fileChooser.setDialogType( JFileChooser.SAVE_DIALOG );
int result = fileChooser.showOpenDialog( this );
if ( result == JFileChooser.CANCEL_OPTION )
return;
File fileName = fileChooser.getSelectedFile();
if ( fileName == null || fileName.getName().equals( "" ) )
JOptionPane.showMessageDialog( this, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE );
else{
try{
recordfile = new ObjectOutputStream( new FileOutputStream( fileName ) );
}
catch ( IOException ioException ) {
JOptionPane.showMessageDialog( this, "Error Opening File",
"Error", JOptionPane.ERROR_MESSAGE );
}
}
}
//method for saving information
public void SaveToFile( ActionEvent event ){
boolean done = false;
for( int counter = 0; counter < records; counter++ ){
try{//save list and flight num to database
recordfile.writeObject( List[ counter ] );
recordfile.writeObject( flightNum );
recordfile.flush();
done = true;
}
catch( IOException ioException ){
JOptionPane.showMessageDialog( this, "Error writing to file",
"IO Exception", JOptionPane.ERROR_MESSAGE);
CloseFile();
}
}
if( done ){
JOptionPane.showMessageDialog( this, "Records Saved!!!",
"File Access", JOptionPane.INFORMATION_MESSAGE );
saveButton.setEnabled( false );
}
dayComboBox.setEnabled( false );
destinationComboBox.setEnabled( false );
}
//close file after loading or saving is done
public void CloseFile(){
try{
recordfile.close();
System.exit( 0 );
}
catch( IOException ioException ){
JOptionPane.showMessageDialog( this, "Error Closing File", "Error",
JOptionPane.ERROR_MESSAGE );
System.exit( 1 );
}
}
//method for loading information from an existing file
public void LoadFromFile(ActionEvent event){
boolean done = false;
count = -1;
while( !done ){
count++;
try{
List[ count ] = ( PassengerData ) recordedfile.readObject();
flightNum = ( String ) recordedfile.readObject();
}
catch( EOFException endOfFileException ){
JOptionPane.showMessageDialog( this,
"All records loaded from file!", "End of File",
JOptionPane.INFORMATION_MESSAGE );
done = true;
}
catch( ClassNotFoundException classNotFoundException ){
JOptionPane.showMessageDialog( this, "Unable to create object!",
"Class Not Found", JOptionPane.ERROR_MESSAGE );
}
catch( IOException ioException ){
JOptionPane.showMessageDialog( this,
"Error during read from file!", "Read Error",
JOptionPane.ERROR_MESSAGE );
}
}
addButton.setEnabled( true );
deleteButton.setEnabled( true );
dayComboBox.setEnabled( false );
destinationComboBox.setEnabled( false );
dataEntryAllowed();
displayInfo();
}
//clear data when creating new list of passengers
public void ClearData(){
FirstNameField.setText( "" );
LastNameField.setText( "" );
mealComboBox.setSelectedIndex( 0 );
classComboBox.setSelectedIndex( 0 );
customerArea.setText( "# Name\t\tMeal\tClass\tSeat \n" );
flightField.setText( "" );
deleteField.setText( "" );
searchField.setText( "" );
searchField1.setText( "" );
dayComboBox.setSelectedIndex( 0 );
if ( destinationComboBox.getSelectedIndex() == 1 )
destinationComboBox.setSelectedIndex( 0 );
noData();
noDate();
}
//allow data to be entered
public void dataEntryAllowed(){
FirstNameField.setEditable( true );
LastNameField.setEditable( true );
mealComboBox.setEnabled( true );
classComboBox.setEnabled( true );
}
public void displaySeatingChart(){
String seat;
String output;
int aisle;
int row;
PassengerData seating[][] = new PassengerData[11][4];
for( int rows = 0; rows < 11; rows++){
for( int column = 0; column < 4; column++ ){
seating[ rows ][ column ] = new PassengerData( "", "", "", "", "", "", 0 );
}
}
output = "\tSeat 1\tSeat 2\tSeat 3\tSeat 4\n\n";
for( int counter = 0; counter <= count; counter++ ){
seat = List[ counter ].getSeat();
row = Integer.parseInt(seat.substring( 5, 6 ));
aisle = Integer.parseInt( seat.substring( 13 , 14 ) );
seating[row - 1][aisle - 1] = List[ counter ];
}
for( int rows = 0; rows < 11; rows++){
output += "Row " + ( rows + 1 ) + "\t ";
if( rows == 6)
output += "------------First Class-------------\nRow " + ( rows + 1 ) + "\t ";
for( int column = 0; column < 4; column++ ){
if( seating[rows][column].getCheckEnter() == 0 )
output += "Empty Seat\t";
else{
if( column == 1 ){
output += seating[rows][column].getLastName().toUpperCase() + ", " +
seating[rows][column].getFirstName().toUpperCase() + "\t";
}
else{
output += seating[rows][column].getLastName().toUpperCase() + ", " +
seating[rows][column].getFirstName().toUpperCase() + "\t";
}
}
}
output += "\n\n";
}
customerArea.setText( output );
}
public void displayTicket(){
String output;
String destination;
String origin;
if( Integer.parseInt(List[ searchCounter ].getflightNo().substring(3,4)) == 1 ){
destination = "Mae Hong Song";
origin = "Chiang Mai";
}
else{
destination = "Chiang Mai";
origin = "Mae Hong Song";
}
output = "<<<<<<<<<<REGIONAL EXPRESS AIRLINES>>>>>>>>>>\n" + "Flight: " +
List[ searchCounter ].getflightNo() + "\tDestination: " + destination + "\tOrigin " + origin + "\tClass: " +
List[ searchCounter ].getClassType() + "\n\nDay: " +
List[ searchCounter ].getflightNo().substring(4,6) + "\nPASSENGER INFO\nLast Name: " +
List[ searchCounter ].getLastName() + "\tFirst Name: " + List[ searchCounter ].getFirstName();
JOptionPane.showMessageDialog( null, output, "REGIONAL EXPRESS AIRLINES TICKET", JOptionPane.PLAIN_MESSAGE );
}
//display information when a file has been loaded
public void displayManifest(){
String output = "# Name\t\tMeal\tClass\tSeat \n";
for( int counter = 0; counter <= count; counter++ ){
output += ( counter + 1 ) + ". " + List[ counter ].getLastName() +
", " + List[ counter ].getFirstName() + "\t\t" +
List[ counter ].getMealType() +
"\t" + List[ counter ].getClassType() + "\t" + List[ counter ].getSeat() + "\n";
}
customerArea.setText( output );
}
public void displayInfo(){
flightField.setText( flightNum );
String output = "# Name\t\tMeal\tClass\tSeat \n";
customerArea.setText( output );
for( int counter = 0; counter < count; counter++ ){
output = ( counter + 1 ) + ". " + List[ counter ].getLastName() +
", " + List[ counter ].getFirstName() + "\t\t" +
List[ counter ].getMealType() +
"\t" + List[ counter ].getClassType() + "\t" + List[ counter ].getSeat() + "\n";
customerArea.append( output );
}
}
//delete an existing record on list
public void deleteRecord(){
//displays error message if incorrect int or data entered
try{
int record = Integer.parseInt( deleteField.getText() );
if ( record > records )
JOptionPane.showMessageDialog( null, "Record number " + record
+ " does not exist" );
else{
List[ record - 1 ] = List[ records - 1 ];
displayInfo();
count--;
records--;
if( records == 0 ){
searchRadio.setEnabled( false );
mainPanel.setVisible( true );
editPanel.setVisible( false );
editRadio.setEnabled( false );
inputRadio.setSelected( true );
}
saveButton.setEnabled( true );
}
}
catch(NumberFormatException numberFormatException){
JOptionPane.showMessageDialog( this,
"Please enter record number!", "Input Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
//edit name at specific record
public void editName(){
try
{
int edit = Integer.parseInt( editField.getText() );
if ( editField.getText().equals( "" ) || edit > records )
JOptionPane.showMessageDialog( null,
"Please choose a valid record" + " to edit" );
else{
String name = changeNameField.getText();
String lname = List[ edit - 1 ].getLastName();
String meal = List[ edit - 1 ].getMealType();
String seat = List[ edit - 1 ].getSeat();
String classT = List[ edit - 1 ].getClassType();
if ( name.equals( "" ) )
JOptionPane.showMessageDialog( null,
"Please enter in all of" + " the information required" );
else{
List[ edit - 1 ] =
new PassengerData( name, lname, meal, seat, classT, flightNum, 1 );
count++;
displayInfo();
count--;
saveButton.setEnabled( true );
}
}
}
catch(NumberFormatException numberFormatException)
{
JOptionPane.showMessageDialog( this,
"Please enter record number!", "Input Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
//edit last name at a specific record
public void editLName(){
try{
int edit = Integer.parseInt( editField.getText() );
if ( editField.getText().equals( "" ) || edit > records )
JOptionPane.showMessageDialog( null, "Please choose a valid record" +
" to edit" );
else{
String name = List[ edit - 1 ].getFirstName();
String lname = changeNameField.getText();
String meal = List[ edit - 1 ].getMealType();
String seat = List[ edit - 1 ].getSeat();
String classT = List[ edit - 1].getClassType();
if ( lname.equals( "" ) )
JOptionPane.showMessageDialog( null, "Please enter in all of" +
" the information required" );
else{
List[ edit - 1 ] = new PassengerData( name, lname, meal, seat, classT, flightNum, 1 );
count++;
displayInfo();
count--;
saveButton.setEnabled( true );
}
}
}
catch(NumberFormatException numberFormatException){
JOptionPane.showMessageDialog( this,
"Please enter record number!", "Input Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
//edit meal at a specific record
public void editMeal(){
try{
int edit = Integer.parseInt( editField.getText() );
if ( editField.getText().equals( "" ) || edit > records )
JOptionPane.showMessageDialog( null, "Please choose a valid record" +
" to edit" );
else{
String name = List[ edit - 1 ].getFirstName();
String lname = List[ edit - 1 ].getLastName();
String mealC = meal[ mealComboBox1.getSelectedIndex() ];
String seat = List[ edit - 1 ].getSeat();
String classT = List[ edit - 1].getClassType();
if ( meal.equals( "" ) )
JOptionPane.showMessageDialog( null, "Please enter in all of" +
" the information required" );
else{
List[ edit - 1 ] = new PassengerData( name, lname, mealC, seat, classT, flightNum, 1 );
count++;
displayInfo();
count--;
saveButton.setEnabled( true );
}
}
}
catch(NumberFormatException numberFormatException)
{
JOptionPane.showMessageDialog( this,
"Please enter record number!", "Input Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
//edit seat number at a specific record
public void editSeat(){
try{
int edit = Integer.parseInt( editField.getText() );
if ( editField.getText().equals( "" ) || edit > records )
JOptionPane.showMessageDialog( null, "Please choose a valid record" +
" to edit" );
else{
String name = List[ edit - 1 ].getFirstName();
String lname = List[ edit - 1 ].getLastName();
String meal = List[ edit - 1 ].getMealType();
String seat = changeNameField.getText();
String classT = List[ edit - 1].getClassType();
if ( seat.equals( "" ) )
JOptionPane.showMessageDialog( null, "Please enter in all of" +
" the information required" );
else{
List[ edit - 1 ] = new PassengerData( name, lname, meal, seat, classT, flightNum, 1 );
count++;
displayInfo();
count--;
saveButton.setEnabled( true );
}
}
}
catch(NumberFormatException numberFormatException)
{
JOptionPane.showMessageDialog( this,
"Please enter record number!", "Input Error",
JOptionPane.INFORMATION_MESSAGE );
}
}
//search for record
public void searchRecord(){
String output = "";
String key = searchField.getText() + " " + searchField1.getText() ;
int found = 0;
//display an error message if information not filled in
if( searchField.getText().equals( "" ) )
JOptionPane.showMessageDialog( null, "Please enter the First name" );
else if ( searchField1.getText().equals( "" ) )
JOptionPane.showMessageDialog( null, "Please enter the Last name" );
else{
for( int count = 0; count <= records - 1; count++ ){
if ( key.equals( List[ count ].getFirstName() + " " +
List[ count ].getLastName() ) )
found = count + 1;
}
if ( found != 0 ){
output = "\n" + found + key + List[ found - 1 ].getSeat();
searchResultArea.append( output );
searchCounter = found - 1;
}
else
searchResultArea.append("\nCustomer not found");
}
}
//compares seat entered to seat numbers on list to check if already exists
public void checkSeat1(){
String seat = changeNameField.getText();
boolean found = false;
for ( int count = 0; count < records; count ++ )
if ( seat.equals( List[ count ].getSeat() ) )
found = true;
if( found == true )
JOptionPane.showMessageDialog( null, "The seat entered has already" +
" been reserved" );
else
editSeat();
}
public static void main( String args[] )
{
AirBox tabbedPaneDemo = new AirBox();
tabbedPaneDemo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}