import java.awt.Image; import java.io.ByteArrayOutputStream; import java.io.InputStream; /** * Read a gif or jpg from the archive jar file, bypassing getResource * broken in Netscape 4.x. we would normally just use: * java.net.URL url = this.getClass().getResource("han.gif" ); * Image hanLogo = createImage( (java.awt.image.ImageProducer) url.getContent()); * * @param gif fully qualified name of the gif or jpg in the jar file e.g. "han.gif". * * @return Image corresponding to the gif/jpg. * You still have to use a MediaTracker to ensure the Image is fully loaded. * @author Roedy Green */ Image prepareImage( String gif ) throws IOException { InputStream is; ByteArrayOutputStream baos; Image image; is = this.getClass().getResourceAsStream ( gif ); if ( is == null ) { throw new IOException ( gif + " not found" ); } baos = new ByteArrayOutputStream(); int c; while ( ( c = is.read() ) >= 0 ) { baos.write( c ); } image = getToolkit().createImage( baos.toByteArray() ); return image; }