-
Bug
-
Resolution: Incomplete
-
P4
-
None
-
1.3.0
-
x86
-
windows_95
Name: rlT66838 Date: 11/17/99
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
Loading animated gif's from the local filesystem using ImageIcon(fileurl)
leads to mediatracker errors (state aborted).
under windows 95 ist the occurence of this error much higher then under
windows nt.
The behaviour of this Applet is as follows:
The ImageIcon should be created in the start() method. But instead the
load status of the ImageIcon
signals an MediaTracker.ABORTED error. The first 5 times we care for
this error and set the ImageIcon back
to zero. Then we ignore the error and the Animated GIF will be displayed
correctly.
So a work arround could be to ignore MediaTracker.ABORTED as ImageIcons
load status.
/***************************************************
*
* A JApplet demonstrating a strange behaviour
* of an ImageIcon loading an animated GIF
*
***************************************************/
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JApplet;
import javax.swing.ImageIcon;
import java.awt.GridLayout;
import java.awt.MediaTracker;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class AnimatedGIF extends JApplet {
// keeps a reference to a successfully created
// ImageIcon
private ImageIcon icon = null;
private int count = 0;
public void start() {
getContentPane().setLayout( new GridLayout( 2, 0 ));
final JLabel lbl = new JLabel( getImageIcon( "hglass.gif" ) );
final JButton btn = new JButton( "try again" );
// try to create the animated GIF ImageIcon again
btn.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ae ) {
lbl.setIcon( getImageIcon( "hglass.gif" ) );
}
}
);
getContentPane().add( btn );
getContentPane().add( lbl );
}
public ImageIcon getImageIcon( String name ) {
if ( icon == null ) {
icon = new ImageIcon( name );
if(icon.getImageLoadStatus()==MediaTracker.ABORTED) {
System.out.print("\naborted: " + name );
// if load status indicates an error, we assume, that
// the ImageIcon could not be created correctly. We
// set it to zero.
// The 5th time we don't do this
if ( count++ < 4 ) icon = null;
}
}
return icon;
}
}
<HTML>
<HEAD>
<TITLE>Animated GIF</TITLE>
</HEAD>
<BODY>
<APPLET CODE="AnimatedGIF.class" WIDTH=405 HEIGHT=305></APPLET>
</BODY>
</HTML>
(Review ID: 97775)
======================================================================
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
Loading animated gif's from the local filesystem using ImageIcon(fileurl)
leads to mediatracker errors (state aborted).
under windows 95 ist the occurence of this error much higher then under
windows nt.
The behaviour of this Applet is as follows:
The ImageIcon should be created in the start() method. But instead the
load status of the ImageIcon
signals an MediaTracker.ABORTED error. The first 5 times we care for
this error and set the ImageIcon back
to zero. Then we ignore the error and the Animated GIF will be displayed
correctly.
So a work arround could be to ignore MediaTracker.ABORTED as ImageIcons
load status.
/***************************************************
*
* A JApplet demonstrating a strange behaviour
* of an ImageIcon loading an animated GIF
*
***************************************************/
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JApplet;
import javax.swing.ImageIcon;
import java.awt.GridLayout;
import java.awt.MediaTracker;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class AnimatedGIF extends JApplet {
// keeps a reference to a successfully created
// ImageIcon
private ImageIcon icon = null;
private int count = 0;
public void start() {
getContentPane().setLayout( new GridLayout( 2, 0 ));
final JLabel lbl = new JLabel( getImageIcon( "hglass.gif" ) );
final JButton btn = new JButton( "try again" );
// try to create the animated GIF ImageIcon again
btn.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ae ) {
lbl.setIcon( getImageIcon( "hglass.gif" ) );
}
}
);
getContentPane().add( btn );
getContentPane().add( lbl );
}
public ImageIcon getImageIcon( String name ) {
if ( icon == null ) {
icon = new ImageIcon( name );
if(icon.getImageLoadStatus()==MediaTracker.ABORTED) {
System.out.print("\naborted: " + name );
// if load status indicates an error, we assume, that
// the ImageIcon could not be created correctly. We
// set it to zero.
// The 5th time we don't do this
if ( count++ < 4 ) icon = null;
}
}
return icon;
}
}
<HTML>
<HEAD>
<TITLE>Animated GIF</TITLE>
</HEAD>
<BODY>
<APPLET CODE="AnimatedGIF.class" WIDTH=405 HEIGHT=305></APPLET>
</BODY>
</HTML>
(Review ID: 97775)
======================================================================