Exemple #1
0
 /**
  * This method represents the application code that we'd like to run on a separate thread. It
  * simulates slowly computing a value, in this case just a string 'All Done'. It updates the
  * progress bar every half second to remind the user that we're still busy.
  */
 Object doWork() {
   try {
     for (int i = 0; i < NUMLOOPS; i++) {
       updateStatus(i);
       if (Thread.interrupted()) {
         throw new InterruptedException();
       }
       Thread.sleep(500);
     }
   } catch (InterruptedException e) {
     updateStatus(0);
     return "Interrupted"; // SwingWorker.get() returns this
   }
   return "All Done"; // or this
 }
Exemple #2
0
  protected Applet createApplet(final AppletClassLoader loader)
      throws ClassNotFoundException, IllegalAccessException, IOException, InstantiationException,
          InterruptedException {
    String code = getCode();

    if (code != null) {
      applet = (Applet) loader.loadCode(code).newInstance();
    } else {
      String msg = "nocode";
      status = APPLET_ERROR;
      showAppletStatus(msg);
      showAppletLog(msg);
      repaint();
    }

    // Determine the JDK level that the applet targets.
    // This is critical for enabling certain backward
    // compatibility switch if an applet is a JDK 1.1
    // applet. [stanley.ho]
    findAppletJDKLevel(applet);

    if (Thread.interrupted()) {
      try {
        status = APPLET_DISPOSE; // APPLET_ERROR?
        applet = null;
        // REMIND: This may not be exactly the right thing: the
        // status is set by the stop button and not necessarily
        // here.
        showAppletStatus("death");
      } finally {
        Thread.currentThread().interrupt(); // resignal interrupt
      }
      return null;
    }
    return applet;
  }
Exemple #3
0
  public void run() {
    try {
      Thread drawthread = new HackThread(drawfun, "Render thread");
      drawthread.start();
      synchronized (drawfun) {
        while (state == null) drawfun.wait();
      }
      try {
        long now, then;
        long frames[] = new long[128];
        int framep = 0, waited[] = new int[128];
        while (true) {
          int fwaited = 0;
          Debug.cycle();
          UI ui = this.ui;
          then = System.currentTimeMillis();
          CPUProfile.Frame curf = null;
          if (Config.profile) curf = uprof.new Frame();
          synchronized (ui) {
            if (ui.sess != null) ui.sess.glob.ctick();
            dispatch();
            ui.tick();
            if ((ui.root.sz.x != w) || (ui.root.sz.y != h)) ui.root.resize(new Coord(w, h));
          }
          if (curf != null) curf.tick("dsp");

          BGL buf = new BGL();
          GLState.Applier state = this.state;
          rootdraw(state, ui, buf);
          if (curf != null) curf.tick("draw");
          synchronized (drawfun) {
            now = System.currentTimeMillis();
            while (bufdraw != null) drawfun.wait();
            bufdraw = new Frame(buf, state.cgl);
            drawfun.notifyAll();
            fwaited += System.currentTimeMillis() - now;
          }

          ui.audio.cycle();
          if (curf != null) curf.tick("aux");

          now = System.currentTimeMillis();
          long fd = bgmode ? this.bgfd : this.fd;
          if (now - then < fd) {
            synchronized (events) {
              events.wait(fd - (now - then));
            }
            fwaited += System.currentTimeMillis() - now;
          }

          frames[framep] = now;
          waited[framep] = fwaited;
          for (int i = 0, ckf = framep, twait = 0; i < frames.length; i++) {
            ckf = (ckf - 1 + frames.length) % frames.length;
            twait += waited[ckf];
            if (now - frames[ckf] > 1000) {
              fps = i;
              uidle = ((double) twait) / ((double) (now - frames[ckf]));
              break;
            }
          }
          framep = (framep + 1) % frames.length;

          if (curf != null) curf.tick("wait");
          if (curf != null) curf.fin();
          if (Thread.interrupted()) throw (new InterruptedException());
        }
      } finally {
        drawthread.interrupt();
        drawthread.join();
      }
    } catch (InterruptedException e) {
    } finally {
      ui.destroy();
    }
  }