コード例 #1
2
  protected boolean setDir(JTextField txf, String strValue) {
    String strTxt = txf.getText();
    String strName = txf.getName();
    boolean bSet = false;

    if ((strTxt == null || strTxt.trim().length() == 0 || strTxt.equals(INFOSTR))
        && strName.equalsIgnoreCase("value")) {
      if (timer != null) {
        timer.cancel();
        txf.setForeground(Color.black);
      }

      bSet = true;
      txf.setText(strValue);
      txf.grabFocus();
    }
    return bSet;
  }
コード例 #2
0
ファイル: MainFrame.java プロジェクト: gaurav/taxref
  /**
   * 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.
  }