Professional Documents
Culture Documents
DONE BY
P.Sathvika(201220467028)
G. Eekshitha(201220467032)
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.
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.*;
{
private int seatCounter = 0;
public ReservationSystem()
exitButton.addActionListener(this);
InstructionsPanel.add(userInstructions);
contentPane.add(InstructionsPanel, BorderLayout.NORTH);
buttonPanel.setLayout(new GridLayout(5,3));
buttonArray[i].addActionListener(this);
buttonPanel.add(buttonArray[i]);
}
contentPane.add(buttonPanel,BorderLayout.CENTER);
exitPanel.add(exitButton);
contentPane.add(exitPanel,BorderLayout.SOUTH);
pack();
String confirmSeat = "Are you sure you want to book this seat?";
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");
{
int choice = JOptionPane.showConfirmDialog(null, confirmQuit, "Confirm Quit",
JOptionPane.YES_NO_OPTION);
if(choice == JOptionPane.NO_OPTION)
e.getActionCommand();
else
System.exit(0);
if(e.getActionCommand().equals("booked"))
if(choice == JOptionPane.YES_OPTION)
buttonArray[i].setActionCommand("unbooked");
e.getActionCommand();
else
buttonArray[i].setActionCommand("booked");
e.getActionCommand();
else
e.getSource();
}
@Override
if (e.getID() == WindowEvent.WINDOW_CLOSING)
if (exit == JOptionPane.YES_OPTION)
System.exit(0);
else
super.processWindowEvent(e);
Login:
RESERVATION FORM: