Animated GIF display in JFrame vs. JApplet

Discussion in 'Java' started by Qu0ll, Jun 24, 2008.

  1. Qu0ll

    Qu0ll Guest

    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)
    _________________________________________________

    [Replace the "SixFour" with numbers to email me]
     
    Qu0ll, Jun 24, 2008
    #1
    1. Advertising

  2. On 2008-06-24 14:17 +0100, Qu0ll allegedly wrote:
    > 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.


    --
    DF.
    to reply privately, change the top-level domain
    in the FROM address from "invalid" to "net"
     
    Daniele Futtorovic, Jun 24, 2008
    #2
    1. Advertising

  3. Qu0ll

    Qu0ll Guest

    "Daniele Futtorovic" <> wrote in message
    news:g3repq$b9u$...
    > On 2008-06-24 14:17 +0100, Qu0ll allegedly wrote:
    >> 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.


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

    --
    And loving it,

    -Qu0ll (Rare, not extinct)
    _________________________________________________

    [Replace the "SixFour" with numbers to email me]
     
    Qu0ll, Jun 26, 2008
    #3
  4. On Jun 26, 7:40 pm, "Qu0ll" <> wrote:
    ...
    > > Simply put your Icon in a JLabel. ...


    > 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'?

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 26, 2008
    #4
  5. Qu0ll

    Qu0ll Guest

    "Andrew Thompson" <> wrote in message
    news:...
    > On Jun 26, 7:40 pm, "Qu0ll" <> wrote:
    > ...
    >> > Simply put your Icon in a JLabel. ...

    >
    >> 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?


    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)
    _________________________________________________

    [Replace the "SixFour" with numbers to email me]
     
    Qu0ll, Jun 26, 2008
    #5
  6. On Jun 26, 11:00 pm, "Qu0ll" <> wrote:
    > "Andrew Thompson" <> wrote in message

    ..
    > > Are you testing off a file system, or server?

    >
    > Just locally at this stage.  


    Tomcat can be good for local testing of applets.
    ...
    > > Have you searched the bug database for
    > > 'applet animated gif'?

    >
    > Not yet.


    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.

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 26, 2008
    #6
  7. Qu0ll wrote:
    > 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,

    --

    Knute Johnson
    email s/nospam/knute2008/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
     
    Knute Johnson, Jun 26, 2008
    #7
  8. On Jun 27, 2:10 am, Knute Johnson <>
    wrote:
    ...
    > Please post the GIF or send it to me so I can try it.


    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 Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 27, 2008
    #8
  9. Andrew Thompson wrote:
    > On Jun 27, 2:10 am, Knute Johnson <>
    > wrote:
    > ...
    >> Please post the GIF or send it to me so I can try it.

    >
    > 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();
    }
    }
    });
    }
    }

    --

    Knute Johnson
    email s/nospam/knute2008/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
     
    Knute Johnson, Jun 27, 2008
    #9
  10. Qu0ll

    Qu0ll Guest

    "Knute Johnson" <> wrote in message
    news:48646e3e$0$4091$...
    > Andrew Thompson wrote:
    >> On Jun 27, 2:10 am, Knute Johnson <>
    >> wrote:
    >> ...
    >>> Please post the GIF or send it to me so I can try it.

    >>
    >> 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)
    _________________________________________________

    [Replace the "SixFour" with numbers to email me]
     
    Qu0ll, Jun 27, 2008
    #10
  11. On Jun 27, 5:05 pm, "Qu0ll" <> wrote:
    ...
    > 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'. ;-)

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 27, 2008
    #11
  12. Andrew Thompson wrote:
    > On Jun 27, 5:05 pm, "Qu0ll" <> wrote:
    > ...
    >> 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'. ;-)
    >
    > --
    > Andrew Thompson
    > http://pscode.org/


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

    --

    Knute Johnson
    email s/nospam/knute2008/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
     
    Knute Johnson, Jun 27, 2008
    #12
  13. Knute Johnson wrote:
    > Andrew Thompson wrote:
    >> On Jun 27, 5:05 pm, "Qu0ll" <> wrote:
    >> ...
    >>> 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'. ;-)
    >>
    >> --
    >> Andrew Thompson
    >> http://pscode.org/

    >
    > 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();
    }
    }
    });
    }
    }

    --

    Knute Johnson
    email s/nospam/knute2008/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
     
    Knute Johnson, Jun 27, 2008
    #13
  14. On Jun 28, 2:48 am, Knute Johnson <>
    wrote:

    > >> 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.

    >
    > 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?

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 28, 2008
    #14
  15. Andrew Thompson wrote:
    > On Jun 28, 2:48 am, Knute Johnson <>
    > wrote:
    >
    >>>> 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.

    >> 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?
    >
    > --
    > Andrew Thompson
    > http://pscode.org/


    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?

    --

    Knute Johnson
    email s/nospam/knute2008/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
     
    Knute Johnson, Jun 28, 2008
    #15
  16. On Jun 29, 3:39 am, Knute Johnson <>
    wrote:
    > Andrew Thompson wrote:

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

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

    ...
    > 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.)

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 29, 2008
    #16
  17. Andrew Thompson wrote:
    > On Jun 29, 3:39 am, Knute Johnson <>
    > wrote:
    >> Andrew Thompson wrote:

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

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

    > ...
    >> 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.)
    >
    > --
    > Andrew Thompson
    > http://pscode.org/


    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.

    --

    Knute Johnson
    email s/nospam/knute2008/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
     
    Knute Johnson, Jun 29, 2008
    #17
  18. On Jun 29, 3:01 pm, Knute Johnson <>
    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.

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jun 29, 2008
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeronimo Bertran

    Creating animated GIF dynamically

    Jeronimo Bertran, Nov 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    515
    Xin Huang [MSFT]
    Nov 14, 2003
  2. Shabam

    Animated GIF handling

    Shabam, Mar 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    371
    Shabam
    Mar 5, 2004
  3. =?Utf-8?B?S29lbiBIb29yZWxiZWtl?=

    reading an animated gif ...

    =?Utf-8?B?S29lbiBIb29yZWxiZWtl?=, Oct 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    540
    =?Utf-8?B?S29lbiBIb29yZWxiZWtl?=
    Oct 10, 2004
  4. =?Utf-8?B?QWw=?=

    Animated GIF affected by location.replace

    =?Utf-8?B?QWw=?=, Oct 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    7,344
    =?Utf-8?B?QWw=?=
    Oct 21, 2004
  5. Z
    Replies:
    3
    Views:
    1,612
Loading...

Share This Page