コード例 #1
0
  /**
   * Starts the print operation. This is quite expensive, and is kicked off in a separate thread.
   */
  public void print() {
    final PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);

    // make a local copy of the object to be printed, for use by the print thread
    // below...

    final Component printMe = getPrintComponent();

    Thread worker =
        new Thread() {
          public void run() {
            if (job.printDialog()) {
              try {
                // need to make sure that no other thread tries to
                // run a print job and set printCompnent at the same
                // time...
                synchronized (this) {
                  printComponent = printMe;
                  job.print();
                  printComponent = null;
                }
              } catch (Exception ex) {
                log.warning("error printing: " + ex);
              }
            }
          }
        };
    worker.start();
  }
コード例 #2
0
ファイル: JCanvas.java プロジェクト: xaleth09/Connect4-AI
 public static void sleep(int ms) {
   try {
     Thread.sleep(ms);
   } catch (Exception e) {
   }
 }