Beispiel #1
0
  /**
   * The Memory Monitor sets up a 5 second Timer which displays the amount of remaining memory
   * (compared to the total memory we have).
   */
  private void setupMemoryMonitor() {
    memoryTimer = new java.util.Timer("Memory monitor", true);

    memoryTimer.schedule(
        new TimerTask() {
          @Override
          public void run() {
            // We need to set this off in the Event Thread.
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    // Calculate the memory we have.
                    long value =
                        (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())
                            / (1024 * 1024);
                    long max = Runtime.getRuntime().maxMemory() / (1024 * 1024);
                    int percentage = (int) (((double) value) / max * 100);

                    // Set the progress bar.
                    progressBar.setMinimum(0);
                    progressBar.setMaximum(100);
                    progressBar.setValue(percentage);

                    progressBar.setString(
                        value + " MB out of " + max + " MB (" + percentage + "%)");
                  }
                });
          }
        },
        new Date(),
        5000); // Every five seconds.
  }
Beispiel #2
0
  protected void doBlink() {
    if (timer != null) timer.cancel();

    timer = new java.util.Timer();
    timer.schedule(
        new TimerTask() {
          public void run() {
            WUtil.blink(validateButton);
          }
        },
        delay,
        delay);
  }