Пример #1
0
  @Override
  public void mousePressed(final MouseEvent e) {
    Performance.gc(3);
    repaint();

    final Runtime rt = Runtime.getRuntime();
    final long max = rt.maxMemory();
    final long total = rt.totalMemory();
    final long used = total - rt.freeMemory();

    final String inf =
        TOTAL_MEM_C
            + Performance.format(max, true)
            + NL
            + RESERVED_MEM_C
            + Performance.format(total, true)
            + NL
            + MEMUSED_C
            + Performance.format(used, true)
            + NL
            + NL
            + H_USED_MEM;

    BaseXDialog.info(gui, inf);
  }
Пример #2
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()) + "");
    }
Пример #3
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!");
 }
Пример #4
0
  @Override
  public void paintComponent(final Graphics g) {
    super.paintComponent(g);

    final Runtime rt = Runtime.getRuntime();
    final long max = rt.maxMemory();
    final long total = rt.totalMemory();
    final long used = total - rt.freeMemory();
    final int ww = getWidth();
    final int hh = getHeight();

    // draw memory box
    g.setColor(Color.white);
    g.fillRect(0, 0, ww - 3, hh - 3);
    g.setColor(GRAY);
    g.drawLine(0, 0, ww - 4, 0);
    g.drawLine(0, 0, 0, hh - 4);
    g.drawLine(ww - 3, 0, ww - 3, hh - 3);
    g.drawLine(0, hh - 3, ww - 3, hh - 3);

    // show total memory usage
    g.setColor(color1);
    g.fillRect(2, 2, Math.max(1, (int) (total * (ww - 6) / max)), hh - 6);

    // show current memory usage
    final boolean full = used * 6 / 5 > max;
    g.setColor(full ? colormark4 : color3);
    g.fillRect(2, 2, Math.max(1, (int) (used * (ww - 6) / max)), hh - 6);

    // print current memory usage
    final FontMetrics fm = g.getFontMetrics();
    final String mem = Performance.format(used, true);
    final int fw = (ww - fm.stringWidth(mem)) / 2;
    final int h = fm.getHeight() - 3;
    g.setColor(full ? colormark3 : DGRAY);
    g.drawString(mem, fw, h);
  }