public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setSize(200, 200);
   shell.open();
   display.timerExec(
       5000,
       new Runnable() {
         public void run() {
           System.out.println("5000");
         }
       });
   display.timerExec(
       2000,
       new Runnable() {
         public void run() {
           System.out.println("2000");
         }
       });
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
Exemple #2
0
  /**
   * Start the animation.
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   */
  public synchronized void start() {
    checkWidget();
    if (active) return;

    active = true;
    showStripes = true;

    final Display display = getDisplay();
    final Runnable[] timer = new Runnable[1];
    timer[0] =
        new Runnable() {
          public void run() {
            if (!active) return;
            GC gc = new GC(AnimatedProgress.this);
            paintStripes(gc);
            gc.dispose();
            display.timerExec(SLEEP, timer[0]);
          }
        };
    display.timerExec(SLEEP, timer[0]);
  }