Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4214785

Plug-in doesn't load images from JAR files

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1, 1.2.0, 1.2.2
    • deploy
    • generic, x86, sparc
    • solaris_2.5, solaris_2.6, windows_95, windows_98, windows_nt

      At least in Netscape Navigator on Solaris,
      Java Plug-in does not load images from JAR
      files.

      For the tutorial, we've worked around this
      (PARTLY) by including the image files alongside
      the JAR files. But this wastes disk space and
      bandwidth, and it DOES NOT WORK across firewalls.
      (I think the firewall is what prevents image files
      from being loaded separately, but the cause might
      be something else; the result is the same, though.)

      This is a major bug that degrades applet performance
      and discourages the use of images in applets. Worse,
      since it doesn't show up all the time, developers
      might miss this bug until they've deployed their
      applets, which is likely to make them very angry
      at us.

      Name: gsC80088 Date: 02/26/99


      I have an applet that works fine under Java 1.1.6 but not
      under 1.2. When the applet starts it first displays a splash
      screen. The splash screen also allows the user to enter their
      user name and password in two TextField objects that are placed
      on top of the graphic. Labels are drawn beside these text fields
      while they are visible. As soon as the OK button is pressed
      the OK and Cancel button that appear under the text fields are
      hidden, as are the text fields.

      The class file for the applet is in one Jar file
      (TstProg5.jar) and the code for displaying the splash screen
      is part of a set of support classes in another Jar file
      (Exodus.jar). The splash screen graphic is in the same Jar
      file as the splash screen class. Both components are in the
      directory 'Exodus' within the Exodus.jar file.

      The splash screen image, together with an animated activity
      bar are loaded using the following code:

        private void imageInit()
        {
             MediaTracker mt = new MediaTracker(this);

             System.out.println("Loading graphics");

             splash = parent.getImage(parent.getDocumentBase(), "Exodus/Splash.jpg");
             anim = parent.getImage(parent.getDocumentBase(), "Exodus/Animbar.jpg");

             mt.addImage(splash, 0);
             mt.addImage(anim, 0);
             buffer = createImage(481, 320);
             gc = buffer.getGraphics();

             try
             {
      mt.waitForAll();
             }
             catch (InterruptedException e)
             {
                 System.out.println("Interrupted waiting for creation of image");
             }

             System.out.println("Splash = " + splash.toString());

        } // End loadImage

      The System.out.println call at the end of the method displays
      the following:

          Splash = sun.awt.windows.WImage@f981df62

      so the image is instantiated to something. Also there is a
      delay between the "Loading graphics" message and the "Splash ="
      message that is appropriately long for the size of the graphics
      and the speed of our network. When the paint routine is called
      (which happens in a loop to animate the activity bar) no
      graphics appear. The paint routine is shown below:

        public void paint(Graphics g)
        {
          try
          {
             gc.drawImage(splash, 0, 0, this);
             if(displayComps)
             {
                 gc.setFont(scrnFont);
                 gc.setColor(Color.white);
                 gc.drawString("Login Id:", 80, 160);
                 gc.drawString("Password:", 80, 195);
             }
             else
             if(animating)
             {
                 gc.drawImage(anim, animXpos + 468, 294, this);
                 gc.drawImage(anim, animXpos, 294, this);
                 if(animXpos < 455)
                     gc.drawImage(anim, animXpos + 936, 294, this);
             }
             g.drawImage(buffer, iset.left, iset.top, this);
          }
          catch (NullPointerException e) {}

        } // End paint

      Again, this works fine under JDK 1.1.6 and the JRE run time
      using the Java Plugin.
      ======================================================================

      Name: rlT66838 Date: 03/02/2000


      Java(TM) Plug-in: Version 1.2.2.p001
      Using JRE version 1.2.2
        User home directory = D:\WINNT\Profiles\prd
      Proxy Configuration: no proxy

      JAR cache enabled.
      Opening http://ip200/cursbug.jar no proxy
      CacheHandler file name: D:\WINNT\Profiles\prd\Temporary Internet
      Files\G97J7G22\cursbug.jar

      1. a)place cursbug.jar and CursorBug.htm on Web Server
         b)Open CursorBug.htm in Web Browser
         c)Cursor disappears when entering JApplet
      *Make sure to remove CustomCursorBug.class and jarImage.class from you local
      path or bug will not appear.
      **The Cursor.gif file is CompuServer Graphics Interchange file version 89a
      Noninterlaced (Size:32x32) 4bit(16 Color) with a transparent background.
      2.
      a)FILE:CustomCursorBug.java
      import javax.swing.JApplet;
      import java.awt.Cursor;
      import java.awt.Image;
      import java.awt.Toolkit;
      import java.awt.Point;
      public class CustomCursorBug extends JApplet{
        public CustomCursorBug(){
        }
        public void init(){
          super.init();
          jarImage ji = new jarImage();
          Image cursorImage = ji.getImageFromJAR("images/Cursor.gif");
          Cursor customCursor =
        Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,new
      Point(1,1),"Custom");
      setCursor(customCursor);
        }
      }
      b)jarImage.java
      import java.awt.*;
      import java.io.InputStream;

      public class jarImage {
          public jarImage() { }
          // returns an Image retrieved from a jar file
          public Image getImageFromJAR(String fileName){
            if( fileName == null )
              return null;
            Image image = null;
            byte[] tn = null;
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            InputStream in = getClass().getResourceAsStream(fileName);
            try{ int length = in.available();
              tn = new byte[length];
              in.read( tn);
              image = toolkit.createImage( tn);
            }
            catch(Exception exc){
              System.out.println( exc +" getting resource " +fileName );
              return null;
            }
            return image;
          }
        }
      c)FILE:CursorBug.htm
      <html>
      <head>
      <title>Cursor Bug</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>
      <body bgcolor="#FFFFFF">
      <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
          width = 100
          height = 100
        
      codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Versi
      on=1,2,2,0">
        <param name=CODE value = CustomCursorBug.class >
        <param name=ARCHIVE value="cursbug.jar">
        <param name="type" value="application/x-java-applet;version=1.2">
        <param name="scriptable" value="false">
        <embed
          type="application/x-java-applet;version=1.2"
          code = CustomCursorBug.class
          archive="cursbug.jar"
          width=100
          height=100
          pluginspage="http://java.sun.com/products/plugin/1.2.2/plugin-install.html"
          scriptable=false>
          <noembed></COMMENT> alt="Your browser understands the &lt;APPLET&gt; tag but
          isn't running the applet." Your browser is completely ignoring
          the &lt;APPLET&gt; tag! </noembed>
        </embed>
      </object>
      </body>
      </html>
      3)No error reported
      4)N/A
      5)N/A
      (Review ID: 101296)
      ======================================================================

            stanleyh Stanley Ho (Inactive)
            kwalrathsunw Kathy Walrath (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: