This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Class Project:  Airline Reservation System Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Class Project:  Airline Reservation System" Watch "Class Project:  Airline Reservation System" New topic
Author

Class Project: Airline Reservation System

Matthew Schexnayder
Greenhorn

Joined: Dec 08, 2009
Posts: 1
Hello, Greenhorns! I've been working this project for a few weeks now, and have hit a small snag. But let me start from the beginning - here's the actual assignment:

Write a program to book seats on a small airplane. 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.

so my question is: how do i get that window to:

a. close when i click "no" or "x"

b. remove a seat's "reserved" status when i click "yes"

thank you all very much in advance!!

here's my code so far:
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Your for loops may be messing you up:



You know which button has been pressed by e.getSource, so there's no need to do either for loop. In your second for loop above, you're changing the text and actioncommands of all buttons (note that your program doesn't truly get locked but rather you must deal with 12 dialogs before the dialogs will quit).

Myself, I'd create a class, say called ReservationSeat, that holds a boolean variable, booked, an int, seatNumber, an int (or better String) variable, confirmationNumber, give it requisite setters and getters, and either create a 2-dimensional array of these guys or perhaps associate JButtons with these objects by using a HashMap<JButton, ReservationSeat>.

e.g.,


If you used a HashMap, then your button listener can be greatly simplified. i.e.,


Note the similar post here: Reservation Java Project

Classmate?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class Project: Airline Reservation System
 
Similar Threads
writeUTF and JComboBox
What's up with a random number like this being displayed 889193265?
Problem with saving a state in calendar program.
last week of class last assignment. Any help is appreciated.
JButton with bad Labels