Animated GIF display in JFrame vs. JApplet

Q

Qu0ll

I have an animated GIF which I would like to display in all its animated
glory in a JFrame based application and in a JApplet. The GIF animates when
displayed in the JFrame by using the paintIcon() method of ImageIcon but the
same code only displays a static icon in the applet.

Is there a reason for this and/or a way to get it to work in the applet? I
am not trying to do anything sophisticated with it just yet, I simply create
a JPanel and override its paintComponent() method to paint the ImageIcon.
As I said, it works fine when the JPanel is in a JFrame but not in a
JApplet.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
D

Daniele Futtorovic

I have an animated GIF which I would like to display in all its animated
glory in a JFrame based application and in a JApplet. The GIF animates
when displayed in the JFrame by using the paintIcon() method of
ImageIcon but the same code only displays a static icon in the applet.

Is there a reason for this and/or a way to get it to work in the
applet? I am not trying to do anything sophisticated with it just yet,
I simply create a JPanel and override its paintComponent() method to
paint the ImageIcon. As I said, it works fine when the JPanel is in a
JFrame but not in a JApplet.

Simply put your Icon in a JLabel. Shouldn't be necessary to interfere
with paintComponent() at all.

This MAY solve your problem.
 
Q

Qu0ll

Daniele Futtorovic said:
Simply put your Icon in a JLabel. Shouldn't be necessary to interfere
with paintComponent() at all.

This MAY solve your problem.

Thanks but it just doesn't want to animate inside an applet even when in a
JLabel :-(

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

Thanks but it just doesn't want to animate inside an applet even when in a
JLabel :-(

Maybe your GIF is just tired. Try mine.
<http://pscode.org/test/animatedlabel/>

Interestingly, I tried that in a variety
of forms, and the first time I saw the GIF
animate in the applet was when it was coming
live off the net.

Are you testing off a file system, or server?

Have you searched the bug database for
'applet animated gif'?
 
Q

Qu0ll

Andrew Thompson said:
Maybe your GIF is just tired. Try mine.
<http://pscode.org/test/animatedlabel/>

Interestingly, I tried that in a variety
of forms, and the first time I saw the GIF
animate in the applet was when it was coming
live off the net.

Are you testing off a file system, or server?

Just locally at this stage. I figured it wasn't going to work off a server
if it didn't work locally. I'll have to give it a try now.
Have you searched the bug database for
'applet animated gif'?

Not yet.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

Just locally at this stage.  

Tomcat can be good for local testing of applets.
...

I vaguely recall hearing there was a problem with
animated GIFs that required establishing a Thread
to animate them. It was to do with paint() or
paintComponent() AFAIR, not specifically applets.

A quick search (of the net in general) failed to
turn up references to that.
 
K

Knute Johnson

Qu0ll said:
I have an animated GIF which I would like to display in all its animated
glory in a JFrame based application and in a JApplet. The GIF animates
when displayed in the JFrame by using the paintIcon() method of
ImageIcon but the same code only displays a static icon in the applet.

Is there a reason for this and/or a way to get it to work in the
applet? I am not trying to do anything sophisticated with it just yet,
I simply create a JPanel and override its paintComponent() method to
paint the ImageIcon. As I said, it works fine when the JPanel is in a
JFrame but not in a JApplet.

Please post the GIF or send it to me so I can try it.

Thanks,
 
K

Knute Johnson

Andrew said:
On Jun 27, 2:10 am, Knute Johnson <[email protected]>
wrote:
...

Maybe the animated GIF I used for that example
will show the behavior for you. It is available
here.. <http://pscode.org/media/#image>

Andrew:

That GIF works fine. I tried my little program below on both Windows XP
and Fedora 9 using both the appletviewer and FireFox 3. I uploaded it
to my website and tried it from there as well. Under XP I tried it with
IE 7 and Opera as well. On XP I am using Sun's 6u10 compiler and
runtime. On F9 I'm using the default OpenJDK 1.6.0. I found no
problems displaying the animated GIF in an ImageIcon in a JLabel.

I did have some problems with the FireFox 3 cache that sent me round the
bend a few times however. That may or may not be the OP's problem. I
think I would still like to try his animated GIF.

http://rabbitbrush.frazmtn.com/atest.html

The JApplet (and yes I know I should really wrap the GUI code in an
EventQueue.invokeLater()).

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;

public class atest extends JApplet {
public void init() {
try {
URL url = new URL(getCodeBase(),"starzoom-thumb.gif");
System.out.println(url);
ImageIcon ic = new ImageIcon(url);
JLabel l = new JLabel(ic);
add(l,BorderLayout.CENTER);
} catch (Exception e) {
e.printStackTrace();
}
}
}


The application

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test extends JPanel {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon ic = new ImageIcon("starzoom-thumb.gif");
JLabel l = new JLabel(ic);
f.add(l,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
 
Q

Qu0ll

Knute Johnson said:
Andrew said:
On Jun 27, 2:10 am, Knute Johnson <[email protected]>
wrote:
...

Maybe the animated GIF I used for that example
will show the behavior for you. It is available
here.. <http://pscode.org/media/#image>

Andrew:

That GIF works fine. I tried my little program below on both Windows XP
and Fedora 9 using both the appletviewer and FireFox 3. I uploaded it to
my website and tried it from there as well. Under XP I tried it with IE 7
and Opera as well. On XP I am using Sun's 6u10 compiler and runtime. On
F9 I'm using the default OpenJDK 1.6.0. I found no problems displaying
the animated GIF in an ImageIcon in a JLabel.

I did have some problems with the FireFox 3 cache that sent me round the
bend a few times however. That may or may not be the OP's problem. I
think I would still like to try his animated GIF.

http://rabbitbrush.frazmtn.com/atest.html

The JApplet (and yes I know I should really wrap the GUI code in an
EventQueue.invokeLater()).

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;

public class atest extends JApplet {
public void init() {
try {
URL url = new URL(getCodeBase(),"starzoom-thumb.gif");
System.out.println(url);
ImageIcon ic = new ImageIcon(url);
JLabel l = new JLabel(ic);
add(l,BorderLayout.CENTER);
} catch (Exception e) {
e.printStackTrace();
}
}
}


The application

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test extends JPanel {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon ic = new ImageIcon("starzoom-thumb.gif");
JLabel l = new JLabel(ic);
f.add(l,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

After a reworking of my applet I have it working fine now. It seems that I
may have been blocking the EDT inadvertently. False alarm.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Andrew Thompson

After a reworking of my applet I have it working fine now.  
Cool.

..It seems that I
may have been blocking the EDT inadvertently.  

I recall a discussion long ago about detecting
code that blocks the EDT. Perhaps the runtime
answer to that is 'throw an animated GIF into
the GUI'. ;-)
 
K

Knute Johnson

Andrew said:
I recall a discussion long ago about detecting
code that blocks the EDT. Perhaps the runtime
answer to that is 'throw an animated GIF into
the GUI'. ;-)

I'm going to have to try that. That's not a bad idea.
 
K

Knute Johnson

Knute said:
I'm going to have to try that. That's not a bad idea.

It works great. Now I need to come up with a little animated EDT
component that can be added to any program.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test extends JPanel {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon ic = new ImageIcon("starzoom-thumb.gif");
JLabel l = new JLabel(ic);
f.add(l,BorderLayout.NORTH);
JButton b = new JButton("Pause EDT");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
Thread.sleep(2000);
} catch (InterruptedException ie) { }
}
});
f.add(b,BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
 
A

Andrew Thompson

It works great.
Cool.

..Now I need to come up with a little animated EDT
component that can be added to any program.

How about a cute little 'animated dog/helper
character'? (ducks..) ;-)

But no - seriously now, if it can be made relevant,
that sounds a good idea, at least for testing.

How about something that animates a Barber
Shop Pole style 'A OK' bar?
 
K

Knute Johnson

Andrew said:
How about a cute little 'animated dog/helper
character'? (ducks..) ;-)

But no - seriously now, if it can be made relevant,
that sounds a good idea, at least for testing.

How about something that animates a Barber
Shop Pole style 'A OK' bar?

I've got to do some research on how animated GIFs work. This is
definitely on the list. The other option is to just animate something
on a JComponent as the drawing is done on the EDT and will block too.

I'm going to have to think about this some more.

How about WAR DUCKS?
 
A

Andrew Thompson

Andrew Thompson wrote: ... ...
How about WAR DUCKS?

I understand the reference to ducks, but War?

(I saw a bizarre WWII propaganda cartoon from
Disney the other day, that showed Daffy Duck
dropping behind German lines to 'smack the
krauts up'. It was the first thing that popped
into mind when you said 'war ducks' a flock of
Daffy's.)
 
K

Knute Johnson

Andrew said:
I understand the reference to ducks, but War?

(I saw a bizarre WWII propaganda cartoon from
Disney the other day, that showed Daffy Duck
dropping behind German lines to 'smack the
krauts up'. It was the first thing that popped
into mind when you said 'war ducks' a flock of
Daffy's.)

There is a credit card ad that runs here night and day on TV. It's two
guys in futuristic clothes on the deck of a starship. The head guy is
saying that now he as time to create his own personalized credit card
with kittens on it, and the other guy says "WAR KITTENS" in this loud
echoing voice. I guess you don't have that down there :). Anyway,
Daffy in army boots is fine too.
 
A

Andrew Thompson

On Jun 29, 3:01 pm, Knute Johnson <[email protected]>
wrote:
...
There is a credit card ad that runs here night and day on TV.  
...I guess you don't have that down there :).  

Yes we have ads on TV here, but whether that one
is showing on TV in Oz I could not say. I do not
have a TV (by decision of "it's sooo boring*, and
I have a great deal more interesting stuff to do").

* Barring the occasional inclusion of v. funny
ads like that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top