/** Initialize the applet */
  public void init() {
    // Create audio clips for pronouncing hours
    for (int i = 0; i < 12; i++)
      hourAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/hour" + i + ".au"));

    // Create audio clips for pronouncing minutes
    for (int i = 0; i < 60; i++)
      minuteAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/minute" + i + ".au"));

    // Add clock and time label to the content pane of the applet
    add(clock, BorderLayout.CENTER);
    add(jlblDigitTime, BorderLayout.SOUTH);
  }
Beispiel #2
0
 /** start */
 @Override
 public void start() {
   super.start();
   showStatus(Compiere.getSummary());
   Splash.getSplash();
   Compiere.startup(true, "Applet"); // 	needs to be here for UI
   new AMenu();
 } //	start
Beispiel #3
0
  public void itemStateChanged(ItemEvent e) {
    Checkbox currentCheckbox = shapeActions.getSelectedCheckbox();
    boolean CheckboxState = currentCheckbox.getState();
    String currentAction = currentCheckbox.getLabel();
    if (CheckboxState) {
      myAction = currentAction;
    } else {
      myAction = "DRAW";
    }

    applet.repaint();
  }
Beispiel #4
0
  public void setSize(Dimension d) {

    super.setSize(d);

    if (offg != null) {
      offscreen = createImage(getWidth(), getHeight());
      offg = offscreen.getGraphics();
    }
    /*
    if(IGView.view!=null){
        IGView.view.setScreenSize(w,h);
        IGView.view.update();
    }
    IGCore.setDisplaySize(d);
    */
  }
 public synchronized Image getImage(URL url) {
   Object o = imageCache.get(url);
   if (o != null) {
     return (Image) o;
   }
   try {
     o = url.getContent();
     if (o == null) {
       return null;
     }
     if (o instanceof Image) {
       imageCache.put(url, o);
       return (Image) o;
     }
     // Otherwise it must be an ImageProducer.
     Image img = target.createImage((java.awt.image.ImageProducer) o);
     imageCache.put(url, img);
     return img;
   } catch (Exception ex) {
     return null;
   }
 }
Beispiel #6
0
 public boolean handleEvent(Event e) {
   if (e.id == Event.WINDOW_DESTROY) this.dispose();
   else if (myApplet != null) {
     if ( // e.id == Event.GOT_FOCUS ||
     e.id == Event.WINDOW_EXPOSE || e.id == Event.WINDOW_DEICONIFY) {
       for (int i = 1; i < nLists; i++) {
         for (int j = 0; j < selectedIndices[i].length; j++) {
           list[i].select(selectedIndices[i][j]);
         }
       }
     } else if (e.id == Event.LIST_SELECT || e.id == Event.LIST_DESELECT) {
       for (int i = 0; i < nLists; i++) {
         selectedIndices[i] = list[i].getSelectedIndexes();
       }
       for (int i = 0; i < nLists; i++) {
         if (e.target == list[i]) {
           Event evt = new Event(this, e.id, new Integer(i));
           myApplet.postEvent(evt);
         }
       }
     }
   }
   return (super.handleEvent(e));
 }
  /**
   * Instantiate a JavaBean.
   *
   * @param classLoader the class-loader from which we should create the bean. If this is null, then
   *     the system class-loader is used.
   * @param beanName the name of the bean within the class-loader. For example "sun.beanbox.foobah"
   * @exception java.lang.ClassNotFoundException if the class of a serialized object could not be
   *     found.
   * @exception java.io.IOException if an I/O error occurs.
   */
  public static Object instantiate(ClassLoader cls, String beanName)
      throws java.io.IOException, ClassNotFoundException {
    java.io.InputStream ins;
    java.io.ObjectInputStream oins = null;
    Object result = null;
    boolean serialized = false;
    java.io.IOException serex = null;
    // If the given classloader is null, we check if an
    // system classloader is available and (if so)
    // use that instead.
    // Note that calls on the system class loader will
    // look in the bootstrap class loader first.
    if (cls == null) {
      try {
        cls = ClassLoader.getSystemClassLoader();
      } catch (SecurityException ex) { // We're not allowed to access the system class loader.
        // Drop through.
      }
    }
    // Try to find a serialized object with this name
    final String serName = beanName.replace('.', '/').concat(".ser");
    final ClassLoader loader = cls;
    ins =
        (InputStream)
            java.security.AccessController.doPrivileged(
                new java.security.PrivilegedAction() {
                  public Object run() {
                    if (loader == null) return ClassLoader.getSystemResourceAsStream(serName);
                    else return loader.getResourceAsStream(serName);
                  }
                });
    if (ins != null) {
      try {
        if (cls == null) {
          oins = new ObjectInputStream(ins);
        } else {
          oins = new ObjectInputStreamWithLoader(ins, cls);
        }
        result = oins.readObject();
        serialized = true;
        oins.close();
      } catch (java.io.IOException ex) {
        ins.close();
        // Drop through and try opening the class.  But remember
        // the exception in case we can't find the class either.
        serex = ex;
      } catch (ClassNotFoundException ex) {
        ins.close();
        throw ex;
      }
    }
    if (result == null) {
      // No serialized object, try just instantiating the class
      Class cl;
      try {
        if (cls == null) {
          cl = Class.forName(beanName);
        } else {
          cl = cls.loadClass(beanName);
        }
      } catch (ClassNotFoundException ex) {
        // There is no appropriate class.  If we earlier tried to
        // deserialize an object and got an IO exception, throw that,
        // otherwise rethrow the ClassNotFoundException.
        if (serex != null) {
          throw serex;
        }
        throw ex;
      }
      /*
       * Try to instantiate the class.
       */

      try {
        result = cl.newInstance();
      } catch (Exception ex) {
        // We have to remap the exception to one in our signature.
        // But we pass extra information in the detail message.
        throw new ClassNotFoundException("" + cl + " : " + ex);
      }
    }
    if (result != null) { // Ok, if the result is an applet initialize it.
      AppletStub stub = null;

      if (result instanceof Applet) {
        Applet applet = (Applet) result;

        // Figure our the codebase and docbase URLs.  We do this
        // by locating the URL for a known resource, and then
        // massaging the URL.

        // First find the "resource name" corresponding to the bean
        // itself.  So a serialzied bean "a.b.c" would imply a
        // resource name of "a/b/c.ser" and a classname of "x.y"
        // would imply a resource name of "x/y.class".

        final String resourceName;

        if (serialized) {
          // Serialized bean
          resourceName = beanName.replace('.', '/').concat(".ser");
        } else {
          // Regular class
          resourceName = beanName.replace('.', '/').concat(".class");
        }

        URL objectUrl = null;
        URL codeBase = null;
        URL docBase = null;

        // Now get the URL correponding to the resource name.

        final ClassLoader cloader = cls;
        objectUrl =
            (URL)
                java.security.AccessController.doPrivileged(
                    new java.security.PrivilegedAction() {
                      public Object run() {
                        if (cloader == null) return ClassLoader.getSystemResource(resourceName);
                        else return cloader.getResource(resourceName);
                      }
                    });

        // If we found a URL, we try to locate the docbase by taking
        // of the final path name component, and the code base by taking
        // of the complete resourceName.
        // So if we had a resourceName of "a/b/c.class" and we got an
        // objectURL of "file://bert/classes/a/b/c.class" then we would
        // want to set the codebase to "file://bert/classes/" and the
        // docbase to "file://bert/classes/a/b/"

        if (objectUrl != null) {
          String s = objectUrl.toExternalForm();

          if (s.endsWith(resourceName)) {
            int ix = s.length() - resourceName.length();
            codeBase = new URL(s.substring(0, ix));
            docBase = codeBase;

            ix = s.lastIndexOf('/');

            if (ix >= 0) {
              docBase = new URL(s.substring(0, ix + 1));
            }
          }
        }

        // Setup a default context and stub.
        BeansAppletContext context = new BeansAppletContext(applet);

        stub = (AppletStub) new BeansAppletStub(applet, context, codeBase, docBase);
        applet.setStub(stub);

        // If it was deserialized then it was already init-ed.
        // Otherwise we need to initialize it.

        if (!serialized) {
          // We need to set a reasonable initial size, as many
          // applets are unhappy if they are started without
          // having been explicitly sized.
          applet.setSize(100, 100);
          applet.init();
        }
        ((BeansAppletStub) stub).active = true;
      }
    }
    return result;
  }
Beispiel #8
0
 /**
  * Gets an AudioClip.
  *
  * @return the audio clip
  */
 public AudioClip getAudioClip() {
   if (clip == null && getURL() != null) {
     clip = Applet.newAudioClip(getURL());
   }
   return clip;
 }
Beispiel #9
0
  /**
   * Load the applet into memory. Runs in a seperate (and interruptible) thread from the rest of the
   * applet event processing so that it can be gracefully interrupted from things like HotJava.
   */
  @SuppressWarnings("deprecation")
  private void runLoader() {
    if (status != APPLET_DISPOSE) {
      showAppletStatus("notdisposed");
      return;
    }

    dispatchAppletEvent(APPLET_LOADING, null);

    // REMIND -- might be cool to visually indicate loading here --
    // maybe do animation?
    status = APPLET_LOAD;

    // Create a class loader
    loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey());

    // Load the archives if present.
    // REMIND - this probably should be done in a separate thread,
    // or at least the additional archives (epll).

    String code = getCode();

    // setup applet AppContext
    // this must be called before loadJarFiles
    setupAppletAppContext();

    try {
      loadJarFiles(loader);
      applet = createApplet(loader);
    } catch (ClassNotFoundException e) {
      status = APPLET_ERROR;
      showAppletStatus("notfound", code);
      showAppletLog("notfound", code);
      showAppletException(e);
      return;
    } catch (InstantiationException e) {
      status = APPLET_ERROR;
      showAppletStatus("nocreate", code);
      showAppletLog("nocreate", code);
      showAppletException(e);
      return;
    } catch (IllegalAccessException e) {
      status = APPLET_ERROR;
      showAppletStatus("noconstruct", code);
      showAppletLog("noconstruct", code);
      showAppletException(e);
      // sbb -- I added a return here
      return;
    } catch (Exception e) {
      status = APPLET_ERROR;
      showAppletStatus("exception", e.getMessage());
      showAppletException(e);
      return;
    } catch (ThreadDeath e) {
      status = APPLET_ERROR;
      showAppletStatus("death");
      return;
    } catch (Error e) {
      status = APPLET_ERROR;
      showAppletStatus("error", e.getMessage());
      showAppletException(e);
      return;
    } finally {
      // notify that loading is no longer going on
      dispatchAppletEvent(APPLET_LOADING_COMPLETED, null);
    }

    // Fixed #4508194: NullPointerException thrown during
    // quick page switch
    //
    if (applet != null) {
      // Stick it in the frame
      applet.setStub(this);
      applet.hide();
      add("Center", applet);
      showAppletStatus("loaded");
      validate();
    }
  }
Beispiel #10
0
  /**
   * Execute applet events. Here is the state transition diagram
   *
   * <pre>{@literal
   *   Note: (XXX) is the action
   *         APPLET_XXX is the state
   *  (applet code loaded) --> APPLET_LOAD -- (applet init called)--> APPLET_INIT --
   *  (applet start called) --> APPLET_START -- (applet stop called) --> APPLET_STOP --
   *  (applet destroyed called) --> APPLET_DESTROY --> (applet gets disposed) -->
   *   APPLET_DISPOSE --> ...
   * }</pre>
   *
   * In the legacy lifecycle model. The applet gets loaded, inited and started. So it stays in the
   * APPLET_START state unless the applet goes away(refresh page or leave the page). So the applet
   * stop method called and the applet enters APPLET_STOP state. Then if the applet is revisited, it
   * will call applet start method and enter the APPLET_START state and stay there.
   *
   * <p>In the modern lifecycle model. When the applet first time visited, it is same as legacy
   * lifecycle model. However, when the applet page goes away. It calls applet stop method and
   * enters APPLET_STOP state and then applet destroyed method gets called and enters APPLET_DESTROY
   * state.
   *
   * <p>This code is also called by AppletViewer. In AppletViewer "Restart" menu, the applet is jump
   * from APPLET_STOP to APPLET_DESTROY and to APPLET_INIT .
   *
   * <p>Also, the applet can jump from APPLET_INIT state to APPLET_DESTROY (in Netscape/Mozilla
   * case). Same as APPLET_LOAD to APPLET_DISPOSE since all of this are triggered by browser.
   */
  @Override
  public void run() {

    Thread curThread = Thread.currentThread();
    if (curThread == loaderThread) {
      // if we are in the loader thread, cause
      // loading to occur.  We may exit this with
      // status being APPLET_DISPOSE, APPLET_ERROR,
      // or APPLET_LOAD
      runLoader();
      return;
    }

    boolean disposed = false;
    while (!disposed && !curThread.isInterrupted()) {
      AppletEvent evt;
      try {
        evt = getNextEvent();
      } catch (InterruptedException e) {
        showAppletStatus("bail");
        return;
      }

      // showAppletStatus("EVENT = " + evt.getID());
      try {
        switch (evt.getID()) {
          case APPLET_LOAD:
            if (!okToLoad()) {
              break;
            }
            // This complexity allows loading of applets to be
            // interruptable.  The actual thread loading runs
            // in a separate thread, so it can be interrupted
            // without harming the applet thread.
            // So that we don't have to worry about
            // concurrency issues, the main applet thread waits
            // until the loader thread terminates.
            // (one way or another).
            if (loaderThread == null) {
              setLoaderThread(new Thread(null, this, "AppletLoader", 0, false));
              loaderThread.start();
              // we get to go to sleep while this runs
              loaderThread.join();
              setLoaderThread(null);
            } else {
              // REMIND: issue an error -- this case should never
              // occur.
            }
            break;

          case APPLET_INIT:
            // AppletViewer "Restart" will jump from destroy method to
            // init, that is why we need to check status w/ APPLET_DESTROY
            if (status != APPLET_LOAD && status != APPLET_DESTROY) {
              showAppletStatus("notloaded");
              break;
            }
            applet.resize(defaultAppletSize);

            if (PerformanceLogger.loggingEnabled()) {
              PerformanceLogger.setTime("Applet Init");
              PerformanceLogger.outputLog();
            }
            applet.init();

            // Need the default(fallback) font to be created in this AppContext
            Font f = getFont();
            if (f == null
                || "dialog".equals(f.getFamily().toLowerCase(Locale.ENGLISH))
                    && f.getSize() == 12
                    && f.getStyle() == Font.PLAIN) {
              setFont(new Font(Font.DIALOG, Font.PLAIN, 12));
            }

            // Validate the applet in event dispatch thread
            // to avoid deadlock.
            try {
              final AppletPanel p = this;
              Runnable r =
                  new Runnable() {
                    @Override
                    public void run() {
                      p.validate();
                    }
                  };
              AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
            } catch (InterruptedException ie) {
            } catch (InvocationTargetException ite) {
            }

            status = APPLET_INIT;
            showAppletStatus("inited");
            break;

          case APPLET_START:
            {
              if (status != APPLET_INIT && status != APPLET_STOP) {
                showAppletStatus("notinited");
                break;
              }
              applet.resize(currentAppletSize);
              applet.start();

              // Validate and show the applet in event dispatch thread
              // to avoid deadlock.
              try {
                final AppletPanel p = this;
                final Applet a = applet;
                Runnable r =
                    new Runnable() {
                      @Override
                      public void run() {
                        p.validate();
                        a.setVisible(true);

                        // Fix for BugTraq ID 4041703.
                        // Set the default focus for an applet.
                        if (hasInitialFocus()) {
                          setDefaultFocus();
                        }
                      }
                    };
                AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
              } catch (InterruptedException ie) {
              } catch (InvocationTargetException ite) {
              }

              status = APPLET_START;
              showAppletStatus("started");
              break;
            }

          case APPLET_STOP:
            if (status != APPLET_START) {
              showAppletStatus("notstarted");
              break;
            }
            status = APPLET_STOP;

            // Hide the applet in event dispatch thread
            // to avoid deadlock.
            try {
              final Applet a = applet;
              Runnable r =
                  new Runnable() {
                    @Override
                    public void run() {
                      a.setVisible(false);
                    }
                  };
              AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
            } catch (InterruptedException ie) {
            } catch (InvocationTargetException ite) {
            }

            // During Applet.stop(), any AccessControlException on an involved Class remains in
            // the "memory" of the AppletClassLoader.  If the same instance of the ClassLoader is
            // reused, the same exception will occur during class loading.  Set the
            // AppletClassLoader's
            // exceptionStatusSet flag to allow recognition of what had happened
            // when reusing AppletClassLoader object.
            try {
              applet.stop();
            } catch (java.security.AccessControlException e) {
              setExceptionStatus(e);
              // rethrow exception to be handled as it normally would be.
              throw e;
            }
            showAppletStatus("stopped");
            break;

          case APPLET_DESTROY:
            if (status != APPLET_STOP && status != APPLET_INIT) {
              showAppletStatus("notstopped");
              break;
            }
            status = APPLET_DESTROY;

            // During Applet.destroy(), any AccessControlException on an involved Class remains in
            // the "memory" of the AppletClassLoader.  If the same instance of the ClassLoader is
            // reused, the same exception will occur during class loading.  Set the
            // AppletClassLoader's
            // exceptionStatusSet flag to allow recognition of what had happened
            // when reusing AppletClassLoader object.
            try {
              applet.destroy();
            } catch (java.security.AccessControlException e) {
              setExceptionStatus(e);
              // rethrow exception to be handled as it normally would be.
              throw e;
            }
            showAppletStatus("destroyed");
            break;

          case APPLET_DISPOSE:
            if (status != APPLET_DESTROY && status != APPLET_LOAD) {
              showAppletStatus("notdestroyed");
              break;
            }
            status = APPLET_DISPOSE;

            try {
              final Applet a = applet;
              Runnable r =
                  new Runnable() {
                    @Override
                    public void run() {
                      remove(a);
                    }
                  };
              AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r);
            } catch (InterruptedException ie) {
            } catch (InvocationTargetException ite) {
            }
            applet = null;
            showAppletStatus("disposed");
            disposed = true;
            break;

          case APPLET_QUIT:
            return;
        }
      } catch (Exception e) {
        status = APPLET_ERROR;
        if (e.getMessage() != null) {
          showAppletStatus("exception2", e.getClass().getName(), e.getMessage());
        } else {
          showAppletStatus("exception", e.getClass().getName());
        }
        showAppletException(e);
      } catch (ThreadDeath e) {
        showAppletStatus("death");
        return;
      } catch (Error e) {
        status = APPLET_ERROR;
        if (e.getMessage() != null) {
          showAppletStatus("error2", e.getClass().getName(), e.getMessage());
        } else {
          showAppletStatus("error", e.getClass().getName());
        }
        showAppletException(e);
      }
      clearLoadAbortRequest();
    }
  }
Beispiel #11
0
 /** ************************************************************************ init */
 @Override
 public void init() {
   super.init();
   TextArea ta = new TextArea(Compiere.getSummary());
   add(ta);
 } //	init
  public GamePanel(String name, int l) {
    setFocusable(true);
    grabFocus();
    addMouseListener(this);
    addMouseMotionListener(this);
    addKeyListener(this);
    keys = new boolean[10000];

    try {
      scoreFont =
          Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("BRLNSB.ttf")))
              .deriveFont(0, 32);
    } catch (IOException ioe) {
      System.out.println("error loading BRLNSB.tff");
    } catch (FontFormatException ffe) {
      System.out.println("Something went wrong with the font.");
    }

    gameBckgrnd = new ImageIcon("Backgroundimage.png").getImage();
    for (int i = 1; i < 7; i++) {
      magnetList.add(new ImageIcon("gamelayerstuff/powerups/magnet" + i + ".png").getImage());
    }

    coinPic = new ImageIcon("gamelayerstuff/coins/byellowcoin1.png").getImage();
    player1 = new Player(200, 300, 100, "sheldon");

    click = false;
    ground = true;
    pause = false;
    lvlClear = false;
    die = false;
    musicOn = true;

    player1.setVelo(150);
    player1.setInvi(true);
    // ------------------------------------------------------------------------------------------------------------------------------------
    // Sound
    coinSound = Applet.newAudioClip(getClass().getResource("coin_pickup_2.wav"));
    clicked = Applet.newAudioClip(getClass().getResource("menu_deselect.wav"));
    starSound = Applet.newAudioClip(getClass().getResource("star.wav"));
    bounce = Applet.newAudioClip(getClass().getResource("grav_step_4.wav"));
    bckGrndMusic = Applet.newAudioClip(getClass().getResource("bgmusic00.wav"));
    bckGrndMusic.loop();
    // ------------------------------------------------------------------------------------------------------------------------------------

    // distance=0;
    score = 0;
    coins = 0;
    level = 1;
    prevLvl = level;
    backy = 0;
    height = backy;
    dieHeight = 0;
    dieMenuHeight = 0;

    pauseB = new SButton(400, 670, "pause", "");
    resumeB = new SButton(100, 500, "resume", "");
    menuB = new SButton(100, 620, "back", "");
    muteB = new SButton(400, 600, "mute", "");
    unmuteB = new SButton(400, 600, "unmute", "");
    // System.out.println("characters/"+name+"/"+name+"35.png");
  }
public class ClockWithAudioOnSeparateThread extends JApplet {
  protected AudioClip[] hourAudio = new AudioClip[12];
  protected AudioClip[] minuteAudio = new AudioClip[60];

  // Create audio clips for pronouncing am and pm
  protected AudioClip amAudio = Applet.newAudioClip(this.getClass().getResource("audio/am.au"));
  protected AudioClip pmAudio = Applet.newAudioClip(this.getClass().getResource("audio/pm.au"));;

  // Create a clock
  private StillClock clock = new StillClock();

  // Create a timer
  private Timer timer = new Timer(1000, new TimerListener());

  // Create a label to display time
  private JLabel jlblDigitTime = new JLabel("", JLabel.CENTER);

  /** Initialize the applet */
  public void init() {
    // Create audio clips for pronouncing hours
    for (int i = 0; i < 12; i++)
      hourAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/hour" + i + ".au"));

    // Create audio clips for pronouncing minutes
    for (int i = 0; i < 60; i++)
      minuteAudio[i] = Applet.newAudioClip(this.getClass().getResource("audio/minute" + i + ".au"));

    // Add clock and time label to the content pane of the applet
    add(clock, BorderLayout.CENTER);
    add(jlblDigitTime, BorderLayout.SOUTH);
  }

  /** Override the applet's start method */
  public void start() {
    timer.start(); // Resume clock
  }

  /** Override the applet's stop method */
  public void stop() {
    timer.stop(); // Suspend clock
  }

  private class TimerListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      clock.setCurrentTime();
      clock.repaint();
      jlblDigitTime.setText(clock.getHour() + ":" + clock.getMinute() + ":" + clock.getSecond());
      if (clock.getSecond() == 0) announceTime(clock.getHour(), clock.getMinute());
    }
  }

  /** Announce the current time at every minute */
  public void announceTime(int h, int m) {
    new Thread(new AnnounceTimeOnSeparateThread(h, m)).start();
  }

  /** Inner class for announcing time */
  class AnnounceTimeOnSeparateThread implements Runnable {
    private int hour, minute;

    /** Get Audio clips */
    public AnnounceTimeOnSeparateThread(int hour, int minute) {
      this.hour = hour;
      this.minute = minute;
    }

    public void run() {
      // Announce hour
      hourAudio[hour % 12].play();

      try {
        // Time delay to allow hourAudio play to finish
        Thread.sleep(1500);

        // Announce minute
        minuteAudio[minute].play();

        // Time delay to allow minuteAudio play to finish
        Thread.sleep(1500);
      } catch (InterruptedException ex) {
      }

      // Announce am or pm
      if (hour < 12) amAudio.play();
      else pmAudio.play();
    }
  }

  public static void main(String[] args) {
    ClockWithAudioOnSeparateThread applet = new ClockWithAudioOnSeparateThread();
    applet.init();
    applet.start();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("ClockWithAudioOnSeparateThread");
    frame.getContentPane().add(applet, BorderLayout.CENTER);
    frame.setSize(400, 320);
    frame.setVisible(true);
  }
}
Beispiel #14
0
 /** destroy */
 @Override
 public void destroy() {
   super.destroy();
   Env.exitEnv(0);
 } //	destroy
Beispiel #15
0
 /** stop */
 @Override
 public void stop() {
   super.stop();
 } //	stop
Beispiel #16
0
  /** Determine JDK level of an applet. */
  private void findAppletJDKLevel(Applet applet) {
    // To determine the JDK level of an applet, the
    // most reliable way is to check the major version
    // of the applet class file.

    // synchronized on applet class object, so calling from
    // different instances of the same applet will be
    // serialized.
    Class<?> appletClass = applet.getClass();

    synchronized (appletClass) {
      // Determine if the JDK level of an applet has been
      // checked before.
      Boolean jdk11Target = loader.isJDK11Target(appletClass);
      Boolean jdk12Target = loader.isJDK12Target(appletClass);

      // if applet JDK level has been checked before, retrieve
      // value and return.
      if (jdk11Target != null || jdk12Target != null) {
        jdk11Applet = (jdk11Target == null) ? false : jdk11Target.booleanValue();
        jdk12Applet = (jdk12Target == null) ? false : jdk12Target.booleanValue();
        return;
      }

      String name = appletClass.getName();

      // first convert any '.' to '/'
      name = name.replace('.', '/');

      // append .class
      final String resourceName = name + ".class";

      byte[] classHeader = new byte[8];

      try (InputStream is =
          AccessController.doPrivileged(
              (PrivilegedAction<InputStream>) () -> loader.getResourceAsStream(resourceName))) {

        // Read the first 8 bytes of the class file
        int byteRead = is.read(classHeader, 0, 8);

        // return if the header is not read in entirely
        // for some reasons.
        if (byteRead != 8) return;
      } catch (IOException e) {
        return;
      }

      // Check major version in class file header
      int major_version = readShort(classHeader, 6);

      // Major version in class file is as follows:
      //   45 - JDK 1.1
      //   46 - JDK 1.2
      //   47 - JDK 1.3
      //   48 - JDK 1.4
      //   49 - JDK 1.5
      if (major_version < 46) jdk11Applet = true;
      else if (major_version == 46) jdk12Applet = true;

      // Store applet JDK level in AppContext for later lookup,
      // e.g. page switch.
      loader.setJDK11Target(appletClass, jdk11Applet);
      loader.setJDK12Target(appletClass, jdk12Applet);
    }
  }
Beispiel #17
0
  RootWindow(Container container, Screen screen, Format[] format, Client c) {
    super(screen.rootId);
    rootwindow = container;
    client = c;
    screen.setRoot((Window) this);
    this.width = (short) (screen.width);
    this.height = (short) (screen.height);
    this.screen = screen;
    depth = screen.rootDepth;
    id = screen.rootId;
    type = DRAWABLE_WINDOW;
    x = y = 0;
    origin.x = 0;
    origin.y = 0;
    clss = (byte) InputOutput;
    for (int i = 0; i < format.length; i++) {
      if (format[i].depth == screen.rootDepth) {
        this.bitsPerPixel = format[i].bpp;
      }
    }
    setVisual(screen.rootVisual);
    setBackgroundIsPixel();
    background.pixel = screen.white;

    setBorderIsPixel();
    border.pixel = screen.black;
    borderWidth = 0;
    Resource.add(this);
    makeOptional();
    attr &= ~(1 << 3); // cursorIsNone

    optional.cursor = Cursor.rootCursor;
    setColormap(screen.defaultColormap);

    //  if(rootwindow instanceof JFrame){
    //    rootwindow.setSize(this.width+10, this.height+30); // ??
    //  }
    //  else{
    rootwindow.setSize(this.width, this.height);
    //  }

    try {
      ddxwindow = (DDXWindow) (Window.dDXWindow.newInstance());
    } catch (Exception e) {
      System.err.println(e);
      /*ddxwindow=new DDXWindowImp();*/
    }

    ddxwindow.init(this);
    ddxwindow.setLocation(0, 0);

    if (rootwindow instanceof Frame) {
      // ((Frame)rootwindow).setLayout(null);
      ((Frame) rootwindow).setResizable(false);
      ((Frame) rootwindow).setMenuBar(null);
      ((Frame) rootwindow).add((java.awt.Component) ddxwindow);
    } else if (rootwindow instanceof Applet) {
      ((Applet) rootwindow).add((java.awt.Component) ddxwindow);
    }
    /*
        else if(rootwindow instanceof JFrame){
          ((JFrame)rootwindow).getContentPane().setLayout(null);
          ((JFrame)rootwindow).setResizable(false);
          ((JFrame)rootwindow).setJMenuBar(null);
          ((JFrame)rootwindow).getContentPane().add((java.awt.Component)ddxwindow);
        }
        else if(rootwindow instanceof JWindow){
          ((JWindow)rootwindow).getContentPane().setLayout(null);
          ((JWindow)rootwindow).getContentPane().add((java.awt.Component)ddxwindow);
        }
        else if (rootwindow instanceof JApplet){
          ((JApplet)rootwindow).setJMenuBar(null);
          ((JApplet)rootwindow).getContentPane().add((java.awt.Component)ddxwindow);
        }
    */
    else {
      rootwindow.add((java.awt.Component) ddxwindow);
    }

    if (screen.windowmode != WeirdX.InBrowser) {
      rootwindow.addNotify();
    } else {
      rootwindow.setVisible(true);
    }
    ddxwindow.setVisible(true);

    {
      rootwindow.validate();
      Insets insets = rootwindow.getInsets();
      rootwindow.setSize(
          this.width + insets.left + insets.right, this.height + insets.top + insets.bottom);
      ddxwindow.setLocation(insets.left, insets.top);
      rootwindow.validate();
    }

    ddxwindow.requestFocus();
    Window.focus.win = id;

    Window.LOCK = rootwindow.getTreeLock();
    Client.LOCK = rootwindow.getTreeLock();
    Resource.LOCK = rootwindow.getTreeLock();

    spriteTrace[0] = this;
    sprite.win = this;
  }