Animated gifs in applets

Ive tried to display an animated gif in an applet and it only shows the first frame. What is the code to do this and it be animated?

IIRC, every time you repaint the applet that contains the gif, the correct frame of the (multi-frame, animated) gif will be rendered.
So if you create a thread that just calls repaint() every half-second or so, you should see the gif move.
Usually it isn't necessary to do this explicitly, because there's already a thread updating state and repainting, for some other purpose.

Similar Messages

  • Animated gif on applets

    how can i paste animated gif on my applet

    this is how i did it
    Icon animgif = new ImageIcon("YouranimatedGIF.gif");
    JLabel l = new JLabel(animgif);
    add(l);
    i can guarantee you that this is not a very good way of doing it but its the only one that i know :)..
    but i hope it helps

  • Applet Parameters For Animated Gif Using AWT

    I need to have my applet except parameters to change from one type of animated gif (dog) to another animated gif (cat). There are two for each animal. If the animal parameter is "dog" the dog1.gif and the dog2.gif will be used for the animation. I'm not too sure on how to go about this.
    private String sDog;
    private String sCat;
    sDog = getParameter("");
    if (sDog.equalsIgnoreCase("dog"))
    How do I add both gifs in the control statement?
    Thanks so much,
    Jeff

    private String sDog;
    private String sCat;
    sDog = getParameter("dog");
    for(int i=1;i<3;i++){
    if (sDog.equalsIgnoreCase("dog" i".gif"))
    //code to display the gif
    remember your parameter should be <b>dog</b>

  • Animated GIF frame loss

    I have an applet that has a JPanel with a JLabel in it. That JLabel was created with an ImageIcon constructor with an animated gif image. The gif has eleven frames (each with replace set) and is set to loop. When I bring up the applet the image animates through the first 7 frames then stops. I can File/Open the gif in Netscape and it looks fine - animates all images and loops. Looking at it with:
    setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION); or FLASH_OPTION
    it looks good until that 7th frame then I start to see flash of grey the size of the JLabel.
    I understand that the ImageObserver defaults to the JLabel. But I have tried directly setting it with no joy. I have also tried calling .flush() on the image with no joy. So I tried a different animated gif and it stopped on the 3rd frame (but also appears fine in a browser).
    I am on day 2 of trying to figure this out (pulling my hair out).
    I cut this down quite a bit, so there may be syntax errors.
    public class RRR extends JApplet implements RRRConsts
    public void init()
    loadImages();
    myJPanel = new MyJPanel();
    contentPane.add(myJPael);
    private void loadImages()
    try
    problemImage = loadImage(new URL(getDocumentBase(),
    "problem.gif"));
    catch (Exception e)
    { logger.log(Level.SEVERE, "Unable to load images", e); }
    private Image loadImage(URL url) throws InterruptedException
    Image image = getImage(url);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    return image;
    MyJPanel myJPanel = null;
    static Image problemImage = null;
    class MyJPanel extends JPanel implements RRRConsts
    MyJPanel()
    setLayout(null);
    setBounds(0,0,468,540);
    setOpaque(false);
    buildUI();
    private void buildUI()
    myLabel = new MyLabel();
    add(myLabel);
    private MyLabel myLabel = null;
    class MyLabel extends JLabel implements RRRConsts, ActionListener
    MyLabel()
    super(new ImageIcon(RRR.problemImage));
    }

    I just had the same problem. It seems that when using an animated gif as ImageIcon it will not be loaded compeltly if it is too large. The maximum seems to be somewhere between 60 - 70 KB.
    I managed to use a higher compression on my gifs to make them smaller, but I haven't found any general solution yet.

  • Animated .gif won't loop a specified amount of times

    I created an animated .gif in photoshop and set it to loop twice. It works fine in every other browser except firefox. Here is a test example:
    http://elliottkirby.com/test/
    The box is set to animate across twice. Any thoughts? I tested setting it to loop "forever" and it works in FF...however the ad I'm creating has a loop time limit. I checked my config settings and image animation is set to normal. Thanks!

    From what I understand of your problem;
    - You have made your own animated gifs
    - With the software to make these gifs you have set them to loop their animations 3 times
    - They loop continuously
    I don't see how java can be expected to interpret the animated gif software instructions to loop only 3 times and would assume that there are various proprietry ways of setting this (an assumption based on applets /javascript etc, that rely on the client-side browser interpreter). So, if you loop your animated gif or have any form of animated gif that you import into your program with getDocumentBase /getCodeBase as a (pre-animated) gif, then this is exactly what I would assume would happen.
    The answer is to seperate your images with eg;-
    smiley1[0];
    smiley1[1];
    smiley1[2];
    run a seperate thread, cycle through them as you wish and stop.
    I'm fairly sure that there is nothing in either the swing libraries or the jmf libraries that can resolve this any other way, so your choices are write extra code and have a pool of threads to control this, or leave it as is.

  • Animated Gif won't stop looping!

    I'll try to format my question as best I can.
    I have created a Java chat applet, and for the Java chat, I have created a "ChatPane" class for displaying the chat. ChatPane is an extension of Canvas, and every time the paint() method is called, the program loops through visible lines of text drawing them on a buffer image, then draws the buffer on the screen.
    My problem lies in animated gifs. In my chatroom, chatters can type textual symbols that will be replaced with an image (or emoticon). I have created my animated icons in a popular animated gif editing program, and I have set particular icons to loop 3 times. The problem is that when the animated icon is displayed in my applet, the animation -doesn't stop- after 3 loops, it loops forever! I can't for the life of me figure out why! Can anyone provide any insight as to why the animations won't stop after 3 loops? The animations work just fine if displayed in a browser by themselves (they stop looping after 3 times)
    Thank you for any help!
    [email protected]
    Tony N.

    From what I understand of your problem;
    - You have made your own animated gifs
    - With the software to make these gifs you have set them to loop their animations 3 times
    - They loop continuously
    I don't see how java can be expected to interpret the animated gif software instructions to loop only 3 times and would assume that there are various proprietry ways of setting this (an assumption based on applets /javascript etc, that rely on the client-side browser interpreter). So, if you loop your animated gif or have any form of animated gif that you import into your program with getDocumentBase /getCodeBase as a (pre-animated) gif, then this is exactly what I would assume would happen.
    The answer is to seperate your images with eg;-
    smiley1[0];
    smiley1[1];
    smiley1[2];
    run a seperate thread, cycle through them as you wish and stop.
    I'm fairly sure that there is nothing in either the swing libraries or the jmf libraries that can resolve this any other way, so your choices are write extra code and have a pool of threads to control this, or leave it as is.

  • Transparency problem with animated gif within AJAX overlay

    Hello all,
    I have designed and animated a loading spinner in Photoshop CS3, which needs to sit within an Ajax overlay, with transparency set to 75.
    I tried exporting the spinner as an animated gif with a transparent background (using Save for Web), but it gave the animation a pixelated outside edge. Does anybody know how to remedy this?
    As the Ajax overlay is semi-transparent, I tried exporting the animated gif with a black background and transparency set to 75%. I ticked the transparency box in the export window, but once it is loading in the Ajax it doesn't seem to be transparent (see here: http://www.chrisgartside.co.uk/flash/Screenshot.jpg)
    Any help is very much appreciated.
    Best wishes,
    ruth.

    I forgot to mention that the Ajax pop-up is fired up from a Flash gaming applet.
    Thanks very much in advance.
    ruth.

  • Using an Animated GIF/JPEGs Effectively

    I have an animated GIF in an applet with around 200 frames, moving at a speed of 6 frames per second. However, when just drawing it in paint(), it looks extremely messy with the flashing. Then I tried another tack, and exported the gif as 200 jpeg files and used double buffering to draw it in a JPanel with the following code:
    public void load()
         images = new ImageIcon[numImages];
         for (int i=0; i<images.length; i++)
              String num = "" + i;
              if (num.length() == 1)
                   num = "00" + i;
              if (num.length() == 2)
                   num = "0" + i;
              images[i] = new ImageIcon(dir + imageNm + num + ".jpg");
         setSize(getPreferredSize());
         startAnim();
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         if (images[currentImage].getImageLoadStatus() == MediaTracker.COMPLETE)
              images[currentImage].paintIcon(this, g, 0, 0);
              currentImage = (currentImage + 1) % numImages;
    public void startAnim()
         if (animTimer == null)
              currentImage = 0;
              animTimer = new Timer(animDelay, this);
              animTimer.start();
         else if (!animTimer.isRunning())
              animTimer.restart();
    public void actionPerformed(ActionEvent e)
         if (currentImage == numImages-1)
              stopAnim();
         repaint();
    public void stopAnim()
         animTimer.stop();
    }However, the outOfMemory Exception appears after loading approximately the first 50 stills. Any suggestions, besides having to extend the memory usage?

    deltacoder, I tried what you suggested in the code below, to keep the images inside an array of 20 and to rotate them as soon as the image is displayed.
    public void init()
         images = new ImageIcon[20];
         for (int i=0; i<20; i++)
              String num = "" + i;
              if (num.length() == 1)
                   num = "00" + num;
              if (num.length() == 2)
                   num = "0" + num;
              images[i] = new ImageIcon(dir + imageNm + num + ".jpg");
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         if (images[currentImage%20].getImageLoadStatus() == MediaTracker.COMPLETE)
              images[currentImage%20].paintIcon(this, g, 0, 0);
              if (currentImage < (numImages-21))
                   String numStr = "" + (currentImage + 20);
                   if (numStr.length() == 1)
                        numStr = "00" + numStr;
                   if (numStr.length() == 2)
                        numStr = "0" + numStr;
                   images[currentImage%20] = new ImageIcon(dir + imageNm + numStr + ".jpg");
              currentImage++;
    }However, for some reason, it is still laggy. Can you perhaps see why from my code? must41, I am also working on your suggestion. In your thread for loading images, shouldn't there be some sleep time? Otherwise, the thread might get ahead of itself and cause outofmemory exception. And from what I know, whenever garbage collect runs, the code will run laggier than usual no matter what. Perhaps, I should have mentioned earlier, but there is also an AudioClip playing in the background (which does take up memory itself) that I like to match to the images (which i know will match because i made the animation using Flash MX), which is why I can't afford the lag from the garbage collecting.
    Perhaps there is a way to combine both of your suggestions?

  • Need help importing animated gif by ImageIcon in Japplet

    Hello. Im new to Java, but I want to import this animated gif with Java in a Japplet using ImageIcon, but it does not work and I would really appreciate if anyone could help me with this.
    import java.applet.*;                                   
    import java.awt.*;   
    import java.net.*;
         public class Bilder extends Japplet{                               
         public ImageIcon(java.net."http://pixelninja.se/kappawin.gif");
      Image[] bild = new Image[1];                            
      int nr=0;                                                
      public void init(){                                     
        setBackground(Color.black);                         
        bild[0] = getImage(getCodeBase(),"4a.gif");     
      public void paint(Graphics g){
        g.drawImage(bild[0],50,50,212,282,this);
    }

    You cant do animated gifs this way.
    Also you should remember that you cannot load images in to an applet if it is hosted somewere else than the host that hosts the applet.
    Esiast way to display an image icon with a animated gif will be creating a Image Label and adding it to the applet.
    Ex:-
    public class MyImageApplet extends JApplet{
       public void init(){
          getConentPane().setLayout(new BorderLayout());
           URL imageURL = getClass().getResource("/myImage.gif"); 
          // Above image file should be in the code base or in the archive file of the applet
          getConentPane().add(new JLabel(new ImageIcon(imageURL)));
    }

  • Animated Gifs in Swing

    Is it possible to draw an animated Gif in a swing gui? I know how I can display animated gifs in an applet, but I really would like to do it in a gui that does not use the class Applet.

    Welcome to the Sun forums.
    KarlStroetmann wrote:
    Is it possible to draw an animated Gif in a swing gui? E.G.
    import javax.swing.*;
    import java.net.URL;
    class ShowGif {
      public static void main(String[] args) throws Exception {
        final URL url = new URL(
          "http://pscode.org/media/starzoom-thumb.gif");
        Runnable r = new Runnable() {
          public void run() {
            ImageIcon ii = new ImageIcon(url);
            JOptionPane.showMessageDialog( null, ii );
        SwingUtilities.invokeLater(r);
    KarlStroetmann wrote:.. I know how I can display animated gifs in an applet, but I really would like to do it in a gui that does not use the class Applet.A JApplet is Swing, and offers all the methods an Applet does. ;)
    Edit 1:
    Note that it is usually necessary to wrap an ImageIcon in a JLabel before display, but JOptionPane does that automatically.
    Edited by: AndrewThompson64 on Jul 10, 2009 5:26 AM

  • Open and edit animated .gif while preserving frame timing

    CS4 Premium Design Edition, Win XP
    I was disappointed with the removal of Image Ready from CS3 because although some of the functionality was placed into Photoshop 10, there was no way to open and edit an existing animated .gif while preserving the timing of each individual frame. I was told on the PS forum at the time that I really needed to use Fireworks. I resented that, because I was very happy with Image Ready and I didn't want to have to learn a new application just to gain functionality that had been included in previous versions of PS/IM.
    I've now got CS4 Premium Design Edition which of course includs Fireworks... and here's what Help has to say on the subject of imported .gifs.
    "Note: When you import an animated GIF, the state delay setting defaults to 0.07 seconds. If necessary, use the States panel to restore the original timing."
    This is no use to me. What if I don't know the individual frame timings? What if there are 200 frames with varying timings?
    Simple question: which current Adobe product is capable of importing a .gif while retaining the frame timings? If anyone knows, or if I've misunderstood the nature of the Fireworks Help quote above, I'd really appreciate some input here. Thanks :)
    Not so simple question: why was an excellent gif-editing application thrown out to have its functionality partially replaced by a bunch of scripts and half-effective workarounds cooked up by desperate users ("import a gif by using the video import and typing *.* into the filename box..")? It's a fair question I think.
    Mark

    Hi Bob, that's not glib at all, it's a reasonable question.
    I uninstalled it along with everything else when I installed CS3, in the reasonable expectation that whatever replaced IR would be at least equal in functionality.
    Perhaps I should just dig out CS2 and install IM from there, but I have some serious reservations about doing so, because I don't know if/how a partial install of CS2 will impact upon my installation of CS4, and I'm not confident of getting support.
    I am also curious to know if/why Adobe actually removed basic functionality without replicating or replacing it in their other software. I really want to know: which recent, currently supported Adobe product
    should I be using in order to regain this functionality? Or do Adobe no longer produce a geniuinely comprehensive .gif-editing application?
    Mark

  • Animated GIF ignoring frame timing

    I am trying to create simple animated GIFs with a few layers
    of text that simply fade in and fade out in sequence. My initial
    attempt worked perfectly. Most frames use the default 7/100's of a
    second delay as they fade. A few frames were manually set to much
    longer delays so that the text pauses, before fading out to be
    replaced by the next text.
    When I reopened the file, to adjust the background color, and
    then re-saved it, the GIF now plays straight through, ignoring the
    timing of each frame. Nothing I do now can get it to pause on the
    appropriate frames. I've tried cutting the symbols out and pasting
    them into a new file, removing the animation from the symbols and
    reapplying it, etc.
    Any ideas, anyone?
    Thanks in advance.

    None, None.

  • Edit animated gif

    Hi,
    How can I edit an animated gif in Photoshop Elements 6 for Mac?
    When I open the file there is just the first frame in one layer - no other layers available.
    Thanks!

    Thanks Barbara!
    Barbara B. wrote:
    ... then bring it to PSE.
    I can't drag the single frames from Preview to PSE, because PSE 6 doesn't run in window mode.
    (Is this improved in the current version?)
    I can only drag the single frames to the desktop (as TIFF files, I guess transparency info is lost then?).
    Barbara B. wrote:
    ... there's a bug beginning in PSE 6 where you can't change the frame delay rate from the default when you save an animated gif.
    What's the default frame delay rate? Maybe it's just what I need.
    Barbara B. wrote:
    You might  want to look into a free program like giffun from stone.com instead.
    Yes that's maybe a better idea. It doesn't have to be free software. Can you recommend something good?
    Thanks again!

  • Can i open and edit animated GIF in Adobe Photoshop Touch?

    Can i open and edit animated GIF in Adobe Photoshop Touch?

    No, only regular static GIF images are supported. The desktop version of Photoshop does support this however.

  • Animated GIFs are ridiculously large - why?

    Hi all,
    I cannot figure out why the animated GIFs I am exporting are
    so massive in file size. For example, I import a small 5-frame
    650Byte GIF. I edit the size of the canvas to pad it to a square
    (from 54x40 to 54x54, or something like that), then I save it with
    the following settings:
    Animated GIF
    Exact Palette
    0 Loss
    4 Colours (5 including alpha channel)
    No dither
    And it comes out as 64.4KB. How can the file size increase by
    100 times with barely any change? Even if I import it, change
    nothing and save the file with the same settings as above, it's
    still 64.4KB. Is Fireworks padding the file with unnecessary
    information or something?
    Thanks for any help,
    John.

    > But the original image is an animated GIF and it's less
    than 1KB big! So
    > how
    > does it increase in size 100 times when I save it
    even if I don't
    > change
    > anything about the image before saving? There is no
    PNG file but I can
    > link
    > you to the original 650 Byte Animated GIF:
    I'm confused. What is this I am looking at. What have you
    done to it to
    make it increase in weight?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Quircus" <[email protected]> wrote in
    message
    news:g6fohk$mip$[email protected]..
    > But the original image is an animated GIF and it's less
    than 1KB big! So
    > how
    > does it increase in size 100 times when I save it
    even if I don't
    > change
    > anything about the image before saving? There is no
    PNG file but I can
    > link
    > you to the original 650 Byte Animated GIF:
    >
    >
    http://www.aotplaza.com/Prod.gif
    >
    > Is it something to do with my settings perhaps? Like
    telling it to save
    > extra
    > information in the file?
    >

Maybe you are looking for