Using animated gif...

I've encountered a problem in displaying animated gif using java Swing.
For my program, I need to display 6 animated gif images. Sometimes I would get all those displayed, but sometimes only 1 or few are displayed.
This problem troubles me until I found that it is the problem of animated gif I've used, because I have tried to replace the animated gif to static ones then every time the images are all displayed.
I need a help urgently. Thanks a lot in advance.

Hi
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Dance extends JFrame 
public Dance()  
     addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
          {     dispose();
               System.exit(0);}});
     getContentPane().setLayout(null);
     setBounds(10,10,400,300);
     JLabel j1 = new JLabel(new ImageIcon("cut1.gif"));
     j1.setBounds(10,30,40,40);
     getContentPane().add(j1);
     JLabel j2 = new JLabel(new ImageIcon("cut2.gif"));
     j2.setBounds(50,70,40,40);
     getContentPane().add(j2);
     JLabel j3 = new JLabel(new ImageIcon("cut3.gif"));
     j3.setBounds(90,110,40,40);
     getContentPane().add(j3);
     JLabel j4 = new JLabel(new ImageIcon("cut4.gif"));
     j4.setBounds(130,150,40,40);
     getContentPane().add(j4);
     setVisible(true);
public static void main (String[] args)
     new Dance();
  Noah

Similar Messages

  • Using animated GIF as JButton icon

    Hi,
    I am trying to use an animated gif as an icon in a JButton.
    Everything works as it should except the animation is static!!
    Screenshots and code are at:
    http://www.beammicrosystems.com/Java/JButton.html
    Anyone got any good ideas?
    Regards,
    Andrew

    well i think you can do this in a label you can watch for a animation like you want a gif so my idea is that you should just make the label as a button and them :
    JLabel label = new JLabel();
    label.setIcon = new ImageIcon("name.gif");
    and put it the setBounds
    label.setBounds(x,y,long,tall);
    and if you want that looks like a button just do this
    label.setBorder(BorderFactory.createRaisedBevelBorder());
    thats all.

  • Using animated gifs  in emails

    I've made an animated gif using flash an am trying to make it
    so the gif appears in my signature at the bottom of every email. I
    can place it in the signature but when I send the email the gif is
    static and doesn't move. Also I'm using a mac and when I recieve an
    animated gif in an email from a PC the gif is also static. I need
    to be able to send animated gifs in emails from PC and Mac using
    Mircosoft Outlook for PC and Entourage for MAC. Any help would be
    much appreciated.
    Cheers,

    this really has nothing to do with flash at all - you have no
    control over this as the recipient of
    your email may not be using an email client that supports
    animated gifs - does your gif work when
    viewed ina web page?
    you must realize there are a myriad ways people check email -
    sometimes via a browser, handheld
    device, email client software, etc...not all support animated
    gifs and the ones that do may have
    that option turned off by user.
    i would consult the support section of the email software
    your recipients use.
    --> **Adobe Certified Expert**
    --> www.mudbubble.com
    --> www.keyframer.com
    Luke H wrote:
    > I've made an animated gif using flash an am trying to
    make it so the gif
    > appears in my signature at the bottom of every email. I
    can place it in the
    > signature but when I send the email the gif is static
    and doesn't move. Also
    > I'm using a mac and when I recieve an animated gif in an
    email from a PC the
    > gif is also static. I need to be able to send animated
    gifs in emails from PC
    > and Mac using Mircosoft Outlook for PC and Entourage for
    MAC. Any help would be
    > much appreciated.
    >
    > Cheers,
    >
    >

  • Datagrid using animated gif or flash

    I have a datagrid that is using an image control for its item
    renderer on one of the columns. That works just fine but I would
    like to be able to display an animated image in the datagrid
    instead of a static one.
    I know flex doesnt support animated gifs but is there any way
    I could make it show one in a data grid?
    Thanks.

    If you are web deployed you can put an animated gif as the image to an iconic button.
    Image items cannot display animated gifs.
    Anything else you can do through a JavaBean if you need to.

  • Using animated gifs with transparent background.

    Hi guys,
    Keynotes 6.2.
    I have been onto apple support with this problem.
    I add a transparent animated gif to my project.
    It show as a movie correctly in the presentation but when exported as quicktime or HTML the movies fail.
    We eventually found out that quicktime does not support animated gifs. ( support.apple.com/kb/ht3775 )
    So I exported the animation onto a folder with all the frames separately and brought them into final cut pro.
    I then followed these tutorials on how to export with transparent background. ( http://provideocoalition.com/mspencer/video/fcp-x-and-alpha-channels and http://www.larryjordan.biz/fcp-export-transparency ).
    I now have a quicktime movie that if I bring back into Final Cut Pro it has a transparent background.
    However when I bring into keynotes it still has a black background. (presumably keynotes does not recognise the  Apple Prores 444).
    Any ideas how I can achieve what I need. ?
    I am using a program called crazytalk animator and can output with transparent background. Animated Gif or a series of image stills BMP, JPEG, TGA or PNG.
    Cheers
    SteveW

    This has been an ongoing issue for me since I switched from Powerpoint to Keynote. Most of the animated gifs with transparent backgrounds that I used with Powerpoint are no longer transparent in Keynote. You may want to search for those earlier threads on this topic...
    To summarize: I've had to open up my animated gifs in After Effects and use the Color Key effect to restore transparency, with mixed success.
    Good luck!

  • Possible to Use Animated GIF as Rollover Image?

    Before I spend a lot of time on development...does anyone
    know if it's possible to use an animated GIF as a rollover image in
    Captivate? I'm developing an e-Learning course for a
    Sarbannes-Oxley application, and I want to be able to hover over an
    object, then have a rollover graphic describe the hover target in
    more detail...the catch being that I want the description to look
    like a scrolling stock ticker.
    I'm sure Flash is probably the ideal development environment
    for this idea, but that project is way beyond my Flash skills at
    this point...
    Thanks!

    I know you can load and display a PNG image just the way you do for a GIF/JPEG one :
    ImageIcon myIcon = new ImageIcon("my_icon.png");but I don't think many others formats are recognized by j2se... you can simply try to load a BMP file to find out.

  • I am having major issues importing Animated gif's into Adobe Captivate

    Hi everyone
    Captivate 7 (64 bit) keeps crashing when i import animate gifs into flash.
    It's a serious workflow issue for us as the project requires animated gifs.
    I don't have any files to supply for this query as i can't even import gif's into a blank doc.
    Has any one found a solution for this issue ?
    Adobe ??  Have you got a fix for this bug ?
    Thanks in advance
    Nick

    How were the GIF's created? Which version of 7 do you use, you can see the complete version number under Help, About Captivate.
    I have been using animated GIF's in 7, they were created with Photoshop. And I know that each frame in the animation has to have a duration that is not 0secs.

  • Animated GIF not cycling frames in Tomcat

    I have pages that use animated gif files to get across a point.
    In the IDE, they cycle the images as they should
    SunAppserver cycles them properly.
    I only get the first frame in Tomcat (5.5.7)
    Over on the java.net, I saw this on a page concerning JAI:
    GIF
    The decoder supports animated GIF files and GIF files with transparent background. Only the first frame of an animated GIF file may be loaded via JAI; subsequent frames must be obtained via direct use of the ancillary codec classes.
    Um, am I missing something, or is this a Tomcat problem ?

    You just need transparency in your file. Not sure if it has to be pre-multiplied. In graphic converter you need to remove the backgrounds. Haven't used GC in years so can't say how you can be sure it's gone but in Photoshop, Illustrator and After Effects you can choose to have a checkerboard background to tell you when you are seeing 'thru' the image and by how much (the overall opacity or mask of the whole image if that doesn't confuse the issue).
    If you are using PS images they will almost certainly generated with a set of rectangles including a perimeter cropping box and white background and these need to go either before it's bitmapped in a vector base app or the relevant pixels erased after it has been bit mapped in GC. As previously mentioned, if you have a unique bkgd colour, colour selecting/keying are some ways to do this). Much faster for >10 images to generate the plots without the bkgd but this may not be possible, what software is source material coming from?
    I regularly bring in vector based moving art-work into keynote with alpha from Adobe AE, Apple Quartz and rendered .mov files. Some codecs (H.264) don't support a separate alpha channel (RGBA) but PNG (slow to render) and animation and a bunch of others do. Pre-multiplying removes the A channel in the RGBA (by multiplying the R/G/B by the A values) thereby speeding and making compatible with some GPUs/render pipelines.

  • Animated gif in splash hangs or very slow

    Hi
    Not new to programming but quite new to Java. I have tried to find information
    on this already but could not find it. If I missed it and have a double post here,
    please let me know the link to the other post.
    I have a application built in Java. On my laptop it starts in just 2 seconds.
    On the production machine (AMD Geode based touch panel) the application
    starts in about 30 seconds.
    Due to the startup time I wanted to just the -splash option from javaw.exe
    example:
    D:\dist>javaw -splash:animated.gif -jar hmi.jar
    The animated gif shows immediately and is 4532 bytes large.
    java -version gives the following output:
    java version "1.6.0_07"
    Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
    Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
    But with the animated gif as splash the application takes 3 to 4 minutes
    to start or it does not start at all but only keeps showing the splash.
    If I use a non-animated gif the startup time is almost like the normal 30 seconds.
    Any known issues with startup performance using animated gif as splash,
    or are there any known issues on AMD Geode based systems regarding the
    startup performance and usage of animsted gifs as splash ?

    I just see that the splash is not removed from screen either.
    If I minimize the java application I see the animated gif still
    there on screen.
    I tried this with a normal gif (non animated) and that one
    is also not removed from screen when the application is started

  • Animated Gif Repaint

    I knew I was going to end up here eventually, stupid animated gifs.
    First of all, I get weird drawing artifacts on an animated gif on jkd 1.5, I upped this to 1.6 and everything is cool with displaying the gif. It could be because I'm running JBuilder in a XP VM. I don't really care how to fix this, or if its even fixable, I'm just pointing it out.
    I have an animated gif in an imageicon. The program is hangman, and the gif shows a stick figure walking up onto the podium to get hung. I would like to play the gif once, every time the "New Game" button is clicked. I have tried a variety of things to do so, including JLabel1.repaint(); calling the label again, etc, etc. I'll try to post the relevant bits of my code.
    public class HangFrame
        extends JFrame implements ActionListener {
      public HangFrame()
        try {
          jbInit();
        catch (Exception ex) {
          ex.printStackTrace();
      }jbinit calls the placement of all the items.
        jLabel1.setBounds(new Rectangle(19, 57, 550, 400));
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == start) {
          start();
    ....'start' is my name for the button that reads "New Game".
    The start method contains:
    ImageIcon maingif = new ImageIcon( (ClassLoader.getSystemResource(
            "hang1.gif")));
         jLabel1.setIcon(maingif);
    //I've been trying different stuff right here, like repaint.The image displays correctly, and runs once (per the setting I gave it in flash, or thats how java does it).
    I've searched extensively (seems I got lucky by just managing to get it to display once :D). I saw that I might have to flush the image or something like that, but I'm not really sure what that means. I've never had any experience with the graphics and paint component, most of the work we do in class is console and algorithm stuff. I got bored over break and made my hangman into a swing app. I'd appreciate any help.
    Oh, and sorry if this should be in the swing subforum, I figured my issue was too basic for it.
    Edited by: rpk5000 on Dec 31, 2007 8:52 AM

    rpk5000 wrote:
    This is where you're wrong. Dipshits like you post **** like this all the time when it's readily available information that can be searched for WITHOUT >hosing up our forums.Great, give me a link, or even a search term to use on google or these forums. Before you give me search terms, you might want to actually check and make sure the answer is somewhere there...are you out of your freakin mind?!?!?!
    go to google and type "java gif animation"
    you think you're the first person to want to do this?!?!
    moreover, search the forums here
    you think you're the first person to ask for this here?!?!
    You would think "repainting an imageicon animated gif java" would give a page that has the answer on it within the first 10 results but....
    I'm looking for a page that simply says, take your imageicon and call.... (repaint();) or whatever to make it run one more time.Did you even read the API for ImageIcon! It took me 2 seconds to find the information for animating gifs as imageicons.
    Well Java just sucks now doesn't it. Stop using animated gifs and Java since they suck. There, problem solved!I like Java a lot, I'm just saying, in certain instances it seems to fall short.No, YOU fall short. I found the solution in 3 seconds.
    This is a "New to Java" subforum, if you can't handle helping people in a pleasant manner, that shows you respect the other person, what do you think people will think of you and java. If I spent more time on forums like this, and was looking at which language to try, I doubt I would pick java.I don't care what you think of me OR Java. I'm tired of noobs wasting forum resources with this crap. Once I was new to everything, but I went to the library and when the internet came along i learned how to search it!
    Critical thinking people. Don't we teach this in schools any more?!
    When it becomes an Internet joke (http://thedailywtf.com/Articles/plz-email-me-teh-codez.aspx) about how bad the sun forums are, well, you really need to reconsider what you want to do with your life.
    LMAO! You are the daily WTF!
    Edited by: wpafbuser1 on Dec 31, 2007 1:52 PM

  • Animated gif layered above background image

    I have a static background image which is displayed in a JPanel. I need to display animated gifs at certain positions on the base image. For every new frame of the animation, the paint method is called whcih attempts to load the entire base image + all the new animated images which is extremely slow!. It also means the animated gif keeps on getting loaded, and seldom gets beyond the first frame.
    Im sure many people have had to do something like this. Is the solution to draw the gifs on the glasspane (or use layered panes), and to have a seperate paint method? or is their a simple approach like setting a special clip area.

    thanks for the help...
    The size of the background image is approx 400*400 pixels (gif or jpg), and the icons are 25*25, and have between 1 and 6 frames.
    Here comes the code... I havent finished with the mediatracker stuff, but youll get the idea Im sure.
      public void paint(Graphics g) {
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(image,0);
        try {tracker.waitForID(0);}
        catch (InterruptedException e){}
        g.drawImage(image, 0, 0, this); //draw background image (approx 400*400 pixels)
        int ICON_ID = -1;
        Image img;
        //draw all the icons...
        //all icons have between 1 and 6 frames. 25*25 pixels.   
        for (int i = 0; i < icon_IDs.size(); i++) {
          try {
            ICON_ID = new Integer(icon_IDs.elementAt(i).toString()).intValue();
            Point p = dm.getIconPosition(ICON_ID);
            if (isAlarm(ICON_ID)) {        //ITS AN ALARM - use animated gif
              img = getAlarmImage(ICON_ID);
            else                          //NORMAL ICON - no animation
              img = DataDefinition.getImageIcon(dm.getIconType(ICON_ID)).getImage();
            tracker.addImage(img,0);
            try {tracker.waitForID(0);}
            catch (InterruptedException e){}
            int width = DataDefinition.getSize(dm.getIconType(ICON_ID)).width;
            int height = DataDefinition.getSize(dm.getIconType(ICON_ID)).height;
            g.setClip(p.x, p.y, p.x+width, p.y+height);
            g.drawImage(img, p.x, p.y, p.x+width, p.y+height, 0,0,img.getWidth(this),img.getHeight(this),this);
          catch (SQLException sqle) {
            System.out.println("Could not find position of icon : " + ICON_ID);
      }

  • Animated GIF won't animate or not even show at all

    I have been using animated GIF with no problem so far but now with iWeb 08 sometimes it works with certain GIFs documents or sometimes won't with other GIFs documents. Why ? And what can I do about this ? What is the solution ?
    Message was edited by: Ti-Jean

    Well Bababooey if you're comparing yourself to a Apple Genius Bar then you should already know my answer, your snarky remark get a snarky reply.  Why would I go to a salesperson to fix my computer problem when I can go directly go to the source itself.  I used to sell Apple computers over 8 years ago and was apple certified before the Genius bar existed. If I am to go about fixing an issue I can't fix on my own I will go to the source itself meaning Apple's programmers and developers - being UI UX Developer myself I know they should have QA'd all platforms and troubleshooted any arising issues. 
    This was also the first time in the 20 years I've been using a Mac that I even attempted to go on this forum which i thought would put me in connection with a certified Apple representative.  This turned out to be a complete waste of time just being a public forum with no Apple employee involved.  I was hoping to find a quick fix but in turn I was only frustrated with stupid responses such as yours that were in no way an answer to my original question. 
    BTW I fixed the issue on my own and without your help or Apples help. I'm glad if all forums point here regarding this issue because I now have the answer. The answer I was looking for from someone earlier was as simple as this {Download Maverick and reinstall the platform - it will take an hour to do but afterward 10.9.2 was installed and my computer is now able to shutdown and restart without having to do a hard boot.}  No more software update bar at top and no problems with my drive which I told both you and Grant - I know my computer better than you and I've probably been using them longer than you. 
    So again Babowa you were so wrong...... and I am right.
    Again anyone having the same problem, I suggest reinstalling Maverick and you'll be suprised 10.9.2 will work fine.

  • Animation /animated gifs

    hi all
    i was trying to use animated gifs in a game. The problem comes when I run the animated gif. The previous images of the gif remain on the screen. When I use any imaging software to view the animated gif it comes up correctly. My first question is it a problem with my animated gif or do I need to do something in Java. if the answer is I need to do something in java, could someone please help and tell me what I need to do.

    you could of always said.....
    save the animated gifs as individual gifs and cycle through them in the code?
    probably been easier, no?

  • Animated gif picture support for iphone 4s or iphoto app

    i love it to use animated gif pictures in the imessage chat, but it is still not possible to view these pictures in the camera roll or in iphoto.
    would bw great if apple would make it work to play gif pictures in original size.
    ether in iphoto or in the iphone camera roll
    editing gif in iphoto would be freakin awesome

    It's not likely that Apple will add gif animation support into iPhoto, not even the desktop application supports it.
    As far as viewing animated gifs saved in your camera roll, there has been a work around to select the gif and share it using the "Email Photo" option. The gif will play while in the email compose box and when you're done viewing it you can simply press cancel to quit the compose email mode.
    Search the app store there are lots of apps that allow you create animated gifs and you may even find some that will let you view them more easily.

  • Animated GIF causes popup to hang?

    Hi:
    We have started using animated GIFs heavily in Teststand popups for about the last year and half. As we have used this feature more and more, we have had more and more reports of Teststand hanging after acknowledging the popups.
    The problem is very intermittant. But it is reproducible. See attached files. All the sequence does is call a non-modal teststand popup over and over that displays an animated image. The popup is set to timeout after one second (just for convenience of reproducing the problem). The sequence consistently hangs within a couple minutes. Behavior is the same in the sequence editor or the CVI user interface. If the sequence is changed such that no image is displayed by the popup, the sequence does not hang.
    We are using Teststand 4.0.1f1. Let me know how to resolve this, as it is quite a major issue with us. 
    Thanks,
    Dave
    Solved!
    Go to Solution.

    dsteel,
    Take a look at the following thread, http://forums.ni.com/ni/board/message?board.id=330​&message.id=22997#M22997. Basically there is some code that the TestStand step type uses from the CVI RTE to display non-BMP images in an IE control. Specifically, to display the IE ActiveX control, the step type must create an STA thread to display the dialog and it uses some threading functions from the CVI RTE to do it. There is a slight chance that when the step type waits for the STA thread to complete, the CVI function function to wait for the thread can sometimes miss its event, so the step type ends up waiting forever for the STA to complete, even though it already did.
    If you would like to discuss this in more detail, please contact us by using http://ni.com/ask
    Message Edited by Josh W. on 03-13-2009 11:49 AM
    Message Edited by Josh W. on 03-13-2009 11:51 AM
    Josh W.
    Certified TestStand Architect
    Formerly blue

Maybe you are looking for