You are on page 1of 8

Mini project

AIRLINE RESERVATION SYSTEM

DONE BY

P.Sathvika(201220467028)

G. Eekshitha(201220467032)

SIVA SIVANI DEGREE COLLEGE


NOVEMBER 2023
Our assigment is about AIR LINE RESERVATIOM SYSTEM. The plane has four rows each with 3 seats.
Initially all seats are available and are labeled Seat 1 through Seat 12. Create a graphical user interface
for this assignment. Use an array of 12 labeled buttons to represent the seats. The program should be
event driven.

When a button is clicked, a confirmation dialog box must be displayed. This dialog box must have yes,
no, and cancel buttons. If the yes button is clicked, then the label is changed to indicate that the seat is
booked. If either the no or cancel button is clicked the dialog box closes and no additional action is
taken. After the last seat has been reserved, the program must display a message box indicating that all
seats have been booked.

If a button marked as booked is clicked, then the program must display a dialog box indicating that the
seat is booked and another seat must be selected. This dialog box requires an OK button only. Note: If
you would like to add "unbook" functionality to the program you may do so for extra credit. The user
must have an authorization code to "unbook" a seat.

Create an exit button to terminate the program. If the user clicks the exit button, a dialog box must be
displayed to confirm that the user really wants to quit the program. The confirmation dialog box must
have yes, no, and cancel buttons. If the user clicks the yes button then the GUI closes and the program
ends.

Create separate panels for an instructional area (labels that contain instructions for the user), the seat
buttons, and the exit button. Use layout managers to arrange the labels in the instructional panel and
the seat buttons in the seat panel.

The frame title bar must display a heading that represents the name of your application (for example,
Acme Airline Reservation System).

Your program must write the button labels to a file when the program terminates. It must also read the
labels from the file (if the file exists) when a new session begins so that the button labels are reset to
what they were when the previous session ended. The program must also set a seat counter to
accurately reflect the number of occupied seats.

So far, this has been a relatively easy task. The only thing I'm really having trouble with so far is this
section:
If a button marked as booked is clicked, then the program must display a dialog box indicating that the
seat is booked and another seat must be selected. This dialog box requires an OK button only. Note: If
you would like to add "unbook" functionality to the program you may do so for extra credit. The user
must have an authorization code to "unbook" a seat.

The specific trouble that i'm having is that once i've "booked" a seat, the "seat already booked" confirm
dialog box will not go away, no matter which button i press. i must resort to hitting the stop button in
the netbeans output window.

here's my code so far:

package airlinereservationsystem;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Container;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowEvent;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ReservationSystem extends JFrame implements ActionListener

{
private int seatCounter = 0;

private JLabel userInstructions = new JLabel("Click the button" +

" representing the seat you want " +

"to reserve the seat");

private JButton[] buttonArray = new JButton[12];

private JButton exitButton = new JButton("Click to Exit");

private boolean isReserved = true;

public ReservationSystem()

super("SchexAirlines Reservation System");

addWindowListener(new WindowDestroyer( ));

Container contentPane = getContentPane( );

contentPane.setLayout(new BorderLayout( ));

JPanel InstructionsPanel = new JPanel( );

JPanel buttonPanel = new JPanel( );

JPanel exitPanel = new JPanel( );

//add listener to the exit button

exitButton.addActionListener(this);

exitButton.setToolTipText("Click here when finished");

InstructionsPanel.add(userInstructions);

contentPane.add(InstructionsPanel, BorderLayout.NORTH);

buttonPanel.setLayout(new GridLayout(5,3));

for (int i=0;i<12;i++)

buttonArray[i] = new JButton("Seat " + (i+1));

buttonArray[i].addActionListener(this);

buttonArray[i].setToolTipText("Click to book seat");

buttonPanel.add(buttonArray[i]);

}
contentPane.add(buttonPanel,BorderLayout.CENTER);

exitPanel.add(exitButton);

contentPane.add(exitPanel,BorderLayout.SOUTH);

pack();

public void actionPerformed(ActionEvent e)

String confirmSeat = "Are you sure you want to book this seat?";

String confirmQuit = "Are you sure you would like to quit?";

String seatBooked = "Unbook seat? Click YES to unbook, or NO to " +

"choose another seat.";

for (int i = 0; i < 12; i++)

if (e.getActionCommand( ).equals("Seat " +(i + 1)))

int choice = JOptionPane.showConfirmDialog(null, confirmSeat,

"Confirm Seat Selection",

JOptionPane.YES_NO_OPTION);

if(choice == JOptionPane.YES_OPTION)

buttonArray[i].setText("RESERVED");

buttonArray[i].setToolTipText("Seat Taken");

buttonArray[i].setForeground(Color.red);

buttonArray[i].setActionCommand("booked");

if (e.getActionCommand( ).equals("Click to Exit"))

{
int choice = JOptionPane.showConfirmDialog(null, confirmQuit, "Confirm Quit",

JOptionPane.YES_NO_OPTION);

if(choice == JOptionPane.NO_OPTION)

e.getActionCommand();

else

System.exit(0);

for(int i = 0; i < 12; i++)

if(e.getActionCommand().equals("booked"))

int choice = JOptionPane.showConfirmDialog(null, seatBooked, "Seat " +

"Already Booked", JOptionPane.YES_NO_OPTION);

if(choice == JOptionPane.YES_OPTION)

buttonArray[i].setText("Seat " + (i+1));

buttonArray[i].setActionCommand("unbooked");

e.getActionCommand();

else

buttonArray[i].setActionCommand("booked");

e.getActionCommand();

else

e.getSource();

}
@Override

protected void processWindowEvent(WindowEvent e) {

if (e.getID() == WindowEvent.WINDOW_CLOSING)

int exit = JOptionPane.showConfirmDialog(this, "Are you sure?");

if (exit == JOptionPane.YES_OPTION)

System.exit(0);

else

super.processWindowEvent(e);

Login:
RESERVATION FORM:

You might also like