Guidelines for JAMM-able Applets

JAMM

In order for an applet to be shared successfully under JAMM, the following guidelines must be followed.


Restrictions

Menus and Choiceboxes will not work.
Because there is no corresponding Java component for the platform dependent menu peer, JAMM is unable to intercept events posted to a menu or choicebox.

If the applet needs these widgets, use pure Java alternatives, like Netscape's IFC widgets.

Check for Graphics objects being null and reinstantiate them.
Since the Graphics object is platform dependent and not serializable, JAMM sets all Graphics objects to null.

When using an offscreen image (e.g., for animation double buffering), test that the Graphics object for that image is not null.

            // ...
            Image offImage = null;
            Graphics offGraphics = null;
            // ..

            // Incorrect:
            public void paint(Graphics g) {
              if (offImage == null) {
                offImage = createImage(size().width, size().height);
                offGraphics = offImage.getGraphics();
              }
            }

            // Correct
            public void paint(Graphics g) {
              if (offGraphics == null) {
                offImage = createImage(size().width, size().height);
                offGraphics = offImage.getGraphics();
              }
            }

            // also Correct
            public void paint(Graphics g) {
              if (offImage == null) {
                offImage = createImage(size().width, size().height);
              }
              if (offGraphics == null) {
                offGraphics = offImage.getGraphics();
              }
            }
          
Do not hold a reference to a parent Container.
JAMM may remove a component from its parent, which will invalidate any reference to the parent. Always use java.awt.Component.getParent() when the parent is needed.
          // Incorrect
          Frame parentFrame = null;
          // ...
          if (parentFrame == null) {
              Component comp = this;
              while !(comp instanceof Frame) 
                  comp = comp.getParent();
              parentFrame = (Frame)comp;
          }
          Dialog dialog = new Dialog(floor, parentFrame);      


          // Correct
          Component comp = this;
          while !(comp instanceof Frame) 
              comp = comp.getParent();
          Dialog dialog = new Dialog(floor, (Frame)comp);
          
Do not hold references to externalities
Although JAMM has an approach for handling externalities (FileInputStream, FileOutputStream, Socket, etc.), only one has been implemented. An applet may still retrieve a file and read it, just don't hold the file open. There might be a clash if someone joins the JAMM session during a file read.


Recommendations

Avoid externalities
Although JAMM has an approach for handling externalities (FileInputStream, FileOutputStream, Socket, etc.), only one has been implemented.
Images take a long time to copy
Implement java.io.ObjectOutputStream.writeObject() to set all of the images in an object to null. and java.io.ObjectInputStream.readObject() to reload all of the images from the original URL.

Return to JAMM Main Page

James "Bo" Begole
January 21, 1997