Exemplo n.º 1
0
    /**
     * Called when the user selects a name in the date list. Fetches performance data from the
     * database and displays it in the text fields.
     *
     * @param e The selected list item.
     */
    public void valueChanged(ListSelectionEvent e) {
      if (nameList.isSelectionEmpty() || dateList.isSelectionEmpty()) {
        return;
      }
      String movieName = (String) nameList.getSelectedValue();
      String date = (String) dateList.getSelectedValue();
      /* --- insert own code here --- */

      fields[MOVIE_NAME].setText(movieName);
      fields[PERF_DATE].setText(date);

      Performance p = db.getPerformance(movieName, date);

      fields[THEATER_NAME].setText(p.getTheaterName());
      fields[FREE_SEATS].setText((p.getTotalSeats() - p.getBookedSeats()) + "");
    }
Exemplo n.º 2
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!");
 }