Painting GIF images/using JLabels for GIFs... Somehow, make it work!

Ok, I am basically making an arena for a local multiplayer game for my friends, and across the top of the screen is a title ... lets call the title "Game Title". The entire game is contained in 1 JFrame, including the title, sidebars, and the actual "game" part in the middle. I paint all of the objects in the game by painting them in the JFrame's Graphics when the paint() method is called.
Basically, the window looks like this:
| /\./\./\./\./\....Game Title..../\./\./\./\./\ |
|...........______________..............|
|...........|.--.game area.--..|..............|
|...........|_____________|..............|
Where the /\./\./\'s are animated flames. I have tried to just make them as ImageIcons in JLabels, but no matter what I paint() after the labels are added, the window looks like this:
| /\./\./\./\./\ .......................... /\./\./\./\./\ |
|.........................................................|
|.........................................................|
|.........................................................|
Where the flames are animated, but the "background" is always gray. I then tried to paint them as Images (g.drawImage(new ImageIcon(url).getImage(),0,0,null), but that only leaves the first frame of the animated GIF (in other words, its not animated).
What do I do? I have been reading around the forums, but I cannot find a case where somebody needed the GIF inside a Component that they used for painting...
Thanks for any help that you give!

If you're going to paint use a graphic component to do your painting in and don't add any components to it. The 'paint' method in JFrame is called by swing to draw the JFrame and its components. Using it to do custom painting is tricky. You'll need to call 'super.paint' to allow the container to paint its children. See the method detail in the JFrame api (link is in the Container section of the api). Also check the 'paintComponent' and 'paint' methods in the JComponent api method details section.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Painting extends JPanel
    BufferedImage image;
    public Painting(BufferedImage image)
        this.image = image;
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        g.drawImage(image, 125, 175, this);
    private JPanel getTitlePanel()
        JLabel title = new JLabel("Game Title", JLabel.CENTER);
        JLabel flame1 = new JLabel("flames");
        JLabel flame2 = new JLabel("flames");
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        panel.add(flame1, gbc);
        panel.add(title, gbc);
        panel.add(flame2, gbc);
        return panel;
    public static void main(String[] args) throws IOException
        String path = "images/Bird.gif";
        BufferedImage bi = ImageIO.read(Painting.class.getResource(path));
        Painting painting = new Painting(bi);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(painting.getTitlePanel(), "North");
        f.getContentPane().add(painting);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • My iPod has not been working for a month now and i was hoping that you could help me.The part where you charge and sync the iPod is not connecting.There is defiantly not the lead as we use it for the iPhone and that works please could you help!

    my iPod has not been working for a month now and i was hoping that you could help me.The part where you charge and sync the iPod is not connecting.There is defiantly not the lead as we use it for the iPhone and that works please could you help!
    yours sincerly
    jackfromsurrey

    What I am saying is ..........
    The iPhone HAS to be active making calls on the UK carrier network for the carrier to identify as "theirs" and therefore eligible for the Carrier to unlock
    The way to achieve this is to use a PAYG sim making and receiving calls to establish a customer relationship  with the Carrier and then follow the Carrier's process to unlock
    With a PAYG it usually means adding a specified (by the carrier ) amount  usually £15 /£20 depending on the carrier
    This is how O2 function and according to Gemma  this is how Vodafone work

  • HT1338 where is the update for aperture to make it work with the updated os x yosemite

    where is the update for aperture to make it work with the updated os x yosemite

    The currently sold version of Aperture at the AppStore, Aperture 3.6 is compatible with Yosemite. 
    See the Release notes: Aperture 3.6 Release notes
    If you are running any version of Aperture 3, you should be able to update to this version.  Does the update not show for you?
    The update has been shown automatically for those who had upgraded from Mavericks and been running Aperture 3.5.1. Other users, who skipped Mavericks and Aperture 3.5.1 have reported problems to get the update to show and needed to contact the AppStore Support. The update did not show, if the users tried to update from an earlier version.

  • Displaying Image using JLabel in swings

    I am not understanding how to display a image in swing using JLabel Component.
    I am writing in the following manner:
    // importing necessary packages
    in init() method
    public void init()
    Container cp= getContentPane()
    JLabel jl=new JLabel("Image",new ImageIcon("<image>.gif"),JLabel.CENTER);
    cp.add(jl);
    applet is running and only label msg is displaying but not the image.
    Please help me so that i can solve this problem.where the image is to be placed??and how it has to be included?
    Please provide me the solution.

    cp.add(new JLabel("Image",new ImageIcon(new java.net.URL (getCodeBase(),"Test.gif")),JLabel.CENTER));

  • Script to open images using bridge for photoshop

    hi,
    i am looking for photoshop script to open set of selected images using bridge into photoshop and handle those images into a layers for the active document.
    Thanks,
    Thulasiram.S

    I'm not 100% sure what you are looking for, but this is not the best forum to be looking. You either want the Bridge scripting forum, or the Photoshop one:
    http://forums.adobe.com/community/bridge/bridge_scripting
    http://forums.adobe.com/community/photoshop/photoshop_scripting
    Also, please trim the links from your signature in the future. (I did it for you this time.)
    Harbs

  • Problem in displaying images using JLabel in Netbeans

    hi all,
    i am trying to display an image on JLabel in Netbeans.The image is visible in the design view but not displayed in the runtime.Can anyone help me out with suggestions???

    Duplicate - answer here http://forum.java.sun.com/thread.jspa?threadID=5153605&messageID=9578626#9578626

  • Edit Original w/ Embedded Images: A Script Or Plugin to Make This Work?

    We receive so many files from customers with embedded images rather than links; I'd love if Edit Original would still work with embedded images, perhaps only for those filetypes that it recognizes as being able to open into Photoshop.
    Does anyone know of a script that would add this functionality, or perhaps a plugin?

    Hate to bust your bubble but once a file has been embedded in AI it becomes just raster data without a file type. Not a JPEG, not a PSD, not a TIFF—just raster data. You can open the file with Photoshop and select Images from the Open dialog or open a version in Acrobat and extract the images from there.

  • Inserting a page break below an image using VBA for Word

    Hi all,
    I am trying to have about 50 screen shots in one file, automatically crop and resize each image, then add a page break at the end of each image, but then move down to the next screen shot and repeat this process to the end of the file.
    So far, I have figured out the code to select the image, crop it down to a specific size, then blow the image up to the right size.  When I try to add a page break at the end of those first few commands, it keeps putting the page break above the image. 
    Does anyone have any suggestions?
    Here is the current code I am using to accomplish the above;
    Sub ResizeImage()
        If Word.Selection.Type = wdSelectionInlineShape Then
            Set ishp = Word.Selection.Range.InlineShapes(1)
            ishp.LockAspectRatio = False
            ishp.PictureFormat.CropBottom = 130
            ishp.PictureFormat.CropTop = 220
            ishp.PictureFormat.CropLeft = 340
            ishp.PictureFormat.CropRight = 340
            ishp.Height = InchesToPoints(3.5)
            ishp.Width = InchesToPoints(6.5)
        End If
    ' insertpagebreak Macro
        Selection.TypeParagraph1
        Selection.InsertBreak Type:=wdPageBreak
    End Sub
    Any help would be so appreciated, and also any guideance as to how to get this code to repeat itself until the end of the page (have not even come close to figuring that out yet).  Big picture is to get all screen shots down to the pertinent information
    and then have each image on it's own piece of paper so we can print them out for account reconciliation backup.
    Thank you in advance,
    Larissa Boydston

    Hi Larissa,
    >> When I try to add a page break at the end of those first few commands, it keeps putting the page break above the image.
    The reason of this is that it adds the page break at the start of range. We could adjust the range to deal with it.
    >> also any guideance as to how to get this code to repeat itself until the end of the page
    You could iterate all InlineShape objects of current document or current section range.
    There is the simple code that you could refer to:
    Dim s As Word.InlineShape'For each s In InlineShapes
    For Each s In Word.Selection.Range.InlineShapes
    Range(s.Range.End, s.Range.End).InsertBreak Type:=wdPageBreak
    Next s
    Regards
    Starain
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Naming images using 'Save for Web' based on layer name

    Hi All
    Hope someone can help, I'm a bit stumped!
    I've got a PSD in Photoshop CS4 which is for some T-Shirt Designs. I have 15 colours of shirts, all on 15 different layers. Then I have the design of the t-shirt on the top layer. I want to create 15 images with the design shown on each of the 15 shirt colours.
    Is it possible to automate the saving of the files? ie Always have the top layer (the shirt design) on, but save a file with just one of the shirt layers on, and save the file so the filename reflects the layer name?
    I seem to recall Imageready doing something like this, though maybe it was in the Animation section, its been a while :-)
    Cheers
    Mark

    Have a look at layer comps and File>Scripts>Layer Comps to Files.
    more about layer comps:
    http://help.adobe.com/en_US/photoshop/cs/using/WSfd1234e1c4b69f30ea53e41001031ab64-7870a.h tml
    MTSTUNER

  • Have been using firefox for months; now has quit working properly with the websites I use everyday. What happened?

    It has quit working with "liverez" which is my web based reservation program. The place I login is https://reservations.liverez.com/login.asp?LogOff=True&Return=Res but once I login, the site does not work as it did before. The website that corresponds with this doesn't look right now either. I can't even use my msn email account with firefox now. I have had to go back to using internet explorer. I have not even tried other sites with foxfire at this time. The other sites I use for work. Things that aren't working are that I can't click on things I need to click on, drop downs aren't showing up, pictures are absent, etc. It is all working fine on internet explorer and used to work on firefox until last night.

    Thanks to some hints in several strings, I went back to the Control Panel in XP, clicked on Sounds and Devices, clicked on Audio, then changed the default device to the Realtek HD Audio output I have on my computer. Now I can hear You Tube video sound and other Internet audio fine, at least for now. I will come back if it stops again. Thanks to all who posted.

  • Sites using TALEO for job searches no longer works in 19, worked in last official 18 release

    Company websites which use the TALEO job search/apply app/site, no longer work right in 19, they worked fine in 18.xx. Specially, the job search function does not work right when entering the TALEO job search parameters then hitting SEARCH FOR JOB does nothing. AN example site (which does not require registration) is https://nielsen.taleo.net/careersection/3/jobsearch.ftl?lang=en. If I make selections for JOB FIELD and/or LOCATIOn then hit SEARCH FOR JOB, nothing happends. Sites using TALEO worked fine in the last offical 18.x release. TALEO worksd fine in IE 7&Chrome 25.
    Clearing the cache does not change behavior. Finally did a full FF reset--no change.
    WIN XP SP3 | Dell Dimension 4600 | 1.2 G RAM

    I am running Firefox version 19.0.2 and I have the same problem. I am able to filter using Internet Explorer which I really don't like. Rather than users having to figure out why this isn't working either Taleo needs to fix their scripts or a fix needs to happen in Firefox.

  • DO NOT USE IPHOTO FOR ANY IMPORTANT OR PROFESSIONAL WORK

    I am a freelance photographer in NYC and was using iphoto to organize and view my photos. After my last import, Iphoto not only created new folders for my work but also went in and replace 2 of my existing folders of work. I tried everything from backing up and the rebuilding the library to search with spotlight for my pictures. the thumbnails are still in the cache but all of the orginals are gone and i have many unhappy clients. So i am left to using my unfriendly camera import software, but at least i would lose my information.
    ANOTHER ROTTEN APPLE EXPERIENCE
    ( I still love my mac... but i am just ****** off and need to vent)

    DAKNYC
    Welcome to the Apple Discussions.
    Sorry to hear of your difficulties. Perhaps if you gave us details of your set up and what you did we might be able to help you understand what's gone wrong, or perhaps help you solve the problem. That's what this is, a User-To-User technical help forum. Not a place to vent.
    Have you tried
    http://www.apple.com/feedback/iphoto.html
    Regards
    TD

  • I cannot attache files using Firefox for Hotmail or Yahoo - IE works - help!

    Wed night 3/2 and this am 3/4 cannot attach any files pdf or doc while using Firefox in my Hotmail or yahoo email accounts. I did a virus speep and none was found. I opened internet explorer on the same home computer and was able to attach the files via my email accounts. Any help?

    You have a lot of changes to your setting in the network.http section. These are listed in the More System Details list to the right of your question under "Question Details". Do you recall making those changes, or did you use some kind of browser speedup or tuning software that could have done it?
    To test how Firefox runs "uncustomized" on your system, could you do a two-minute experiment?
    '''Create a new Firefox profile'''
    A new profile will have your system-installed plugins (e.g., Flash) and extensions (e.g., security suite toolbars), but no themes, other extensions, or other customizations. It also should have completely fresh settings databases and a fresh cache folder.
    Exit Firefox and start up in the Profile Manager using Start > search box (or Run):
    firefox.exe -P
    Any time you want to switch profiles, exit Firefox and return to this dialog.
    You'll click the Create Profile button. I recommend using the default location suggested (don't click the button to choose a different folder). Then start Firefox in the new profile you created.
    Do sites work more normally?
    When returning to the Profile Manager, you might be tempted to use the Delete Profile button. But... it's a bit too easy to accidentally delete your "real" profile, so I recommend resisting the temptation. If you do want to clean up later, I suggest making a backup of all your profiles first in case something were to go wrong.

  • Anybody use GarageBand for Drum Corps/Marching Band work?

    I'm not in Drum Corps or anything, but I used to follow that stuff when I was in high school marching band, and I got the idea that GarageBand could potentially be a pretty nifty way to arrange some of that kind of music.
    Just wondering if anybody has done this? Any recommended Jam Packs/other instruments? Other experiences/pros/cons welcome!
    Thanks!

    Try place like these. I have not heard any of these loops myself.
    http://www.audiosparx.com/sa/display/sounds.cfm/soundgroupiid.2696
    http://www.tonehammer.com/?p=357
    http://www.producerloops.com/Smart-Loops-Military-Snare-Grooves-1-Sample-Pack-Do wnload.html

  • Adding a title to a still image in iMovie for iPhone 4

    I would like to add a title for a still image using iMovie for iPhone 4. Is this possible? I can't see an option for this and it seems simple enough. I can add titles on video clips, but not on still images. Any suggestions?

    Thanks Joe, hopefully Apple adds this feature to iMovie soon.

Maybe you are looking for

  • Error in Information Steward when viewing data on Views (Data Insight)

    Hello In SAP Information Steward -> Data Insight -> Project -> Views -> for example selecting "Customer Master Company Code KNB1" -> view data brings this error message: Data Services execution failed for CUSTOMER MASTER COMPANY CODE KNB1. Error : (1

  • Error while switching the cube to plan mode.

    Got an error In the process chain plan mode on step Loading transactional cube ZTPM_T02 - switch not possible when i went to that cube and we have yellow request with Requests without Monitor Log: APO Request or Terminated Request Generation. Regards

  • HT201493 Problem with Find My Friends app

    I cannot remove a mistyped invitation. Message "find my friends is unavailable due to a server error" comes on screen with "ok". item continues to stay as invited??

  • Migrate from Crystal Reports to XMLP?

    We have a bunch of reports implemented with Crystal Reports and we are planning to migrate those reports to XMLP. Is that possible? Dose anyone has the same problem? What is the general process? I have no experience about XMLP before. Thanks in advan

  • Hi imporper functionality of table in jdev 11.1.2.2

    Hi all i am developing ana ppplication in jdev 11.1.2.2 i got an issue. i am having an attribute of type number in db.and in eo its of type bigdecimal. Then im using this vo in my page as table and when i do a createinsert operation i am unable to ge