예제 #1
0
 /**
  * Called when the user clicks the Book ticket button. Books a ticket for the current user to
  * the selected performance (adds a booking to the database).
  *
  * @param e The event object (not used).
  */
 public void actionPerformed(ActionEvent e) {
   if (nameList.isSelectionEmpty() || dateList.isSelectionEmpty()) {
     return;
   }
   if (!CurrentUser.instance().isLoggedIn()) {
     displayMessage("Must login first");
     return;
   }
   String movieName = (String) nameList.getSelectedValue();
   String date = (String) dateList.getSelectedValue();
   /* --- insert own code here --- */
   Performance p = db.getPerformance(movieName, date);
   boolean result = db.makeReservation(p);
   Performance pUpdated = db.getPerformance(movieName, date);
   fields[FREE_SEATS].setText((pUpdated.getTotalSeats() - pUpdated.getBookedSeats()) + "");
   if (result) displayMessage("1 ticket booked for " + movieName);
   else displayMessage("Error!");
 }
예제 #2
0
 /**
  * Perform the entry actions of this pane: clear all fields, fetch the movie names from the
  * database and display them in the name list.
  */
 public void entryActions() {
   clearMessage();
   currentUserNameLabel.setText(CurrentUser.instance().getCurrentUserId());
   fillNameList();
   clearFields();
 }