Please, Please Help Me (.gif Images)

Hello,
I want to cry, I've been trying to include .gif images in my swing applications but am having big problems. I've been reading the forums and trying everything. If I try the most basic of examples just to get it working I still have problems. The code compiles correctly and the panels appear but no pics. I've tried including every different file path version, moving .gifs to different folders, what is the problem, why no pics. I'm running J2SE v 1.4.1_02, please help, I would be so greatful, don't make me cry,
Lucy
import java.awt.*;
import javax.swing.*;
public class JFrameImage extends JFrame
public JFrameImage()
Container c = getContentPane();
JPanel panel = new JPanel()
public void paintComponent(Graphics g)
ImageIcon img = new ImageIcon("globe.gif");
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
panel.setOpaque(false);
ImageIcon icon = new ImageIcon("cat.gif");
JButton button = new JButton(icon);
panel.add(button);
c.add(panel);
public static void main(String[] args)
JFrameImage frame = new JFrameImage();
Image onFrame = Toolkit.getDefaultToolkit().getImage("icon.gif") ;
frame.setIconImage(onFrame);
frame.setSize(200,200);
frame.setLocation(300,200);
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.setVisible(true);

sorry but I think it should be something else.
To locate a File you need it's full name, including the extension. Maybe since the extension wasn't showing it's actual filename was cat.gif.gif? I don't know. Anyway, this is a method I use for all my image retrieving, just put it in some Util-class:  private static HashMap hmImages = new HashMap();
  public static ImageIcon getImage (String name)
    if (hmImages.containsKey(name))
      return (ImageIcon) hmImages.get(name);
    String url = System.getProperty("user.dir") + "/resources/" + name;//or any other directory were all your image-files are under (even in subs, in that case add the subdirectory to the arg name
    try
      ImageIcon ic = new ImageIcon (url);
      if (ic != null)
        hmImages.put(name, ic);
        return ic;
    catch (Exception e)
    System.out.println("Warning: image '" + url + "' not found");
    return null;
  }greetz,
Stijn

Similar Messages

  • Please help, my Canon Image Formula P-215 will not work w/ Mavericks

    Please help, my canon image formula p-215 will not work w/ the new mavericks upgrade, is there a work around?

    I ran into the same problem, I posted what worked for me in another topic in this forum:
    https://discussions.apple.com/message/25208435#25208435
    Hope it helps

  • Please help : invalid fiasco image header , and %...

    yes i'm getting these 2 messages, i'm just trying to reflash but i can't, please help me, i tried changing the name of the images, adding .bin ( on xp ) ... but i just can't reflash please help me, i tried these on win7 32bits, and on xp sp3, i'm getting the same thing please can someone help me . note : my device shows the nokia logo, usb logo..... without a backlight, they are all dark, please guys help me .
    Reality is wrong....dreams are for real... 2pac .
    don't forget to hit that green kudos
    Solved!
    Go to Solution.

    I've been really busy with work.. really really busy.. hopefully this week might start to get a bit quieter..
    Right..
    %m means "File not found or bad file name"
    when you run "flasher-3.5 -F os.bin -f" flasher wil be looking for a file called os.bin.. If it can't find os.bin, it gives you the error %m
    Why does it say %m and not something clearer? That's because of a bug in Nokia's software!
    Ok.. Did you download the zip file I sent you? If so here's how I think we can do this:
    Step 1) Open a CMD window
    Go to the start menu, select run then type CMD
    A black cmd window will pop up.. in that window run these commands exactly:
    cd %ProgramFiles%\maemo\flasher-3.5
    start .
    A windows explorer window will appear. Move this window out of the way.. BUT don't close it
    Step 2) move the bin files
    Find the zip file you downloaded.. double click to open the file
    Inside you'll find two bin files
    Drag both files from the zip file into the explorer window that popped up in step 1
    Now close the zip file window
    Step 3) rename the bin files
    In the windows explorer window into which you dragged the bin files, you have to rename the files
    Click on
    RX-51_2009SE_10.2010.13-2.VANILLA_PR_EMMC_MR0_ARM
    and rename (press F2) the file to emmc
    Click on RX-51_2009SE_10.2010.19-1.003_PR_COMBINED_003_ARM.bin
    and rename (press F2) the file to os
    Step 4) flash the files
    unplug and turn off your phone
    In the black cmd window run this command
    flasher-3.5 -F os.bin -f
    flasher will pause saying "waiting for suitable device"
    Press and hold the U button on your phone and plug it in via usb.. you can let go of the U button when flasher starts doing something
    Once flasher has finished (it will say "completed successfully") you can continue:
    run this command
    flasher-3.5 -F emmc.bin -f -R
    That should be it

  • Please Help me on Image Scaling!!

    I am trying to get a map.jpg to scale to fit the window while still able to zoom in & out with mouselistener(which where I clicked). I am able to zoom in & out but the coordinate is according to the original size. Please help.

    1.I am not familiar with Graphics & Graphics2D. The Following code have problem in showing the map in BufferedImage, which is plotted with small dots on it. Actually, it's the Graphics & Graphics2D coding problem that I am facing. I don't know how to use the function.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    public class GPSMap extends JPanel
    private Image map,scaled;
    private double zoomfac=1;
    private BufferedImage bufi;
    int zoomcx,zoomcy,zoomh,zoomw,w,h,newHeight,newWidth,newx,newy,newcx,newcy;
    public GPSMap()
    System.out.println("Loading GPSStatus");
    this.setLayout(new BorderLayout());
    map = getToolkit().getImage("Map3.jpg");
    MediaTracker track=new MediaTracker(this);
    track.addImage(map,0);
    try{track.waitForID(0);}
    catch(InterruptedException ie){}
    w=map.getWidth(this);
    h=map.getHeight(this);
    bufi=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB_PRE);
    newHeight=650;
    newWidth=(int)(newHeight*w/h);
    scaled=map.getScaledInstance(newWidth,newHeight,map.SCALE_SMOOTH);
    addMouseMotionListener(new MouseMotionAdapter()
    public void mouseMoved(MouseEvent m)
         System.out.println("Move at ["+m.getX()+", "+m.getY()+"]");
    zoomcx = m.getX()-(zoomw/2);
    zoomcy = m.getY()-(zoomh/2);
         newx=(int)(m.getX()*newWidth/w);
         newy=(int)(m.getX()*newHeight/h);
         newcx=newx-(zoomw/2);
         newcy=newy-(zoomh/2);
    if (zoomcx <= 0)
    zoomcx = 0;
    if (zoomcy <= 0)
    zoomcy = 0;
    // if (zoomfac != 1)
    // repaint();
    repaint();
    The following part is an extra but cannot do it.
    addMouseListener(new MouseAdapter()
    public void mouseReleased(MouseEvent m)
    if (m.getModifiers() == InputEvent.BUTTON3_MASK)
    zoomfac = zoomfac - 0.21;
    else
    zoomfac = zoomfac + 0.21;
         if (zoomfac <=1)
         zoomfac=1;
    repaint();
    public void paint (Graphics g)
    GPS3 s3=new GPS3();
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
    Graphics2D gc=bufi.createGraphics();
    gc.setColor(Color.red);
    for(int i=0;i<=s3.ix.length;i++){
         gc.drawRect(s3.iy[i]-1,s3.ix[i]-1,2,2);//For plotting purposes, but not yet finish
    gc.drawImage(scaled,50,50,this);
    gc.drawImage(bufi,zoomcx,zoomcy,newcx,newcy,100,70,this);
    P.S. I don't know how to change it to runnable application. Please help.

  • Please help my desktop images, wallpapers gone.

    Please community i need your help. I restored my computer from Lion to lion, before i had Leopard and i had all my favority desktop wallpapers, for example aurora , earth horizon , earth etc..      When i installed for the first time Lion , i got even more desktop images  for ex. Aurora at grey or blue colors those i loved so much . I am so new to mac's ok i did not even know where my folders were, i even wanted to get the same background images for me phone too ^^. But when i did a restore from Lion to Lion means that i erased(and i forgot to backup or search for the desktop images on my mac it was to late ) my disk and got the install all over again , all my desktop wallpapers were gone. Now please if possible for some1 to sent me if he got upgraded from Leopard to Lion and did not erased or kept a backup of desktop images, to simple sent me the folder with all the descibed images i mention, i would be very happy again thank you.

    have had the same problem. also not a computer buff - mine had not been in for work when it would go to sleep after i had shut if down. happened a few times then i lost photos, lots of them. took it to local APPLE repairs and they found nothing, 21 days later.
    last night it did it again - powered off at home and sleeping when i got to the office.
    any advice?

  • Please help, cannot compare images in full screen mode

    I am not able to compare 2 images in full screen mode. I am using a MBP and a ACD 23". The main image will remain in the ACD while the image being compare is being shown in the MBP.
    I am able to compare images in the viewer mode.
    My main display is the ACD 23 which I selected using the display preferences under 'Arrangement' with the menu bar located on the ACD. In Aperture, Secondary Viewer is set to Blank.
    I had also tried different combinations of Main Viewer and Secondary Viewer settings but was not successful.
    Am I missing something? Anyone have the solution?Thanks in advance for any help.
    norheng

    Anyone have any suggestions to using Aperture to edit images using a MBP and ACD so that it best utilize Aperture full screen mode in comparing and narrowing down to the pick.
    I am now trying to use the MBP as the main display and ACD as the secondary. This way I am able to compare images with the MBP in the Browser mode and the ACD display the compare images full screen. It work with the secondary display - ACD set to mirror, span and alternate mode.
    It would be best if only one screen is use and hence save energy consumption (reducing global warming and bill, if it help).
    Thanks in advance for any suggestions or and solutions.
    norheng

  • Please help to load image in the database

    Hi to all. ....
    I need to save image file in the database thru forms ...
    I have some image file in the application server and I need to load it in the database in a Blob col..
    Any help ... ??
    Thank's in advance

    Hi!
    Your forms version is very important.
    If you use forms 10g and you want to load the image on the client, you need webutil.
    If you use forms 6 or you want to load the image from the application server to
    a image item in your form, you can use the read_image_file forms build-in:
    read_image_file ( 'x:\path\image.jpg.', 'JPG', 'block.image_item' );On forms 10g this will be executed on the server and the filename and path has to be
    a physical place on your servers harddisk.
    The image item has to be an item of type image and must be assinged to a blob colum in your table.
    Regards

  • Please Help!! Images for Contacts

    How do I go about getting the contact images to display on my ipod? I have set all images in my Address book, but they don't come over when I sync my contacts. How do I get the images of each individual contact to display in my contacts???

    You need to upgrade to Mac OSX 10.4.3 in order to get photos for contacts.
    http://docs.info.apple.com/article.html?artnum=302493

  • HELP...images not showing up in internet explorer, but show up in Safari

    Somebody please help. My images are showing up fine in Safari
    but when I view them with internet explorer they show an x and
    won't open. I am using layers and tables. Please help!
    Here is my webpage if you need to see code.
    http://www.puddlefoot.com/Tees.html
    Thanks!

    Yonion.jpg is in CMYK colorspace, that's why it doesn't
    display in most
    browsers.
    make it an optimized RGB jpeg file.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • I have made a webpage in HTML with several links to JPGs / GIFs. The text matter opens perfectly but not the images. Please help me

    I have made a web page in HTML with several links to JPGs / GIFs. While text matter opens up perfectly, but not the images. Please help me.
    == This happened ==
    Every time Firefox opened
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CTS Version; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

    URL of that web page?

  • Images in jar file, Please help!!

    Hello,
    This is my code, I am trying to add images to buttons in ToolBar. The code along with images works if I say "java ABC", but dont work(images dont appear) when I jar the files. I have tried all the possible methods, Please help me.
              new2 = new JButton(new ImageIcon("images/new.gif"));
              /*try{
              ClassLoader loader=getClass().getClassLoader();
              URL fileLocation=loader.getResource("./images/new.gif");
              Image img=Toolkit.getDefaultToolkit().getImage(fileLocation);
              new2 = new JButton(new ImageIcon(img));
              }catch(Exception e) { e.printStackTrace(); }*/
              //new2 = new JButton(new ImageIcon(ClassLoader.getSystemResource("images/new.gif")));
              //new2 = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("./images/new.gif"))));
              //ImageIcon oo = new ImageIcon();
              //new2 = new JButton(oo.setImage(getClass().getResource("images/new.gif")));
                   new2.setToolTipText("New");
    Thanks
    James

    Hello,
    The code is too big to post, I am adding the code that is required to get changed, please see it
              open2 = new JButton(new ImageIcon("images/open.gif"));
                   open2.setToolTipText("Open");
                   open2.addActionListener(this);
                   open2.addMouseListener(new MouseAdapter()
                        public void mouseEntered(MouseEvent me)
                             status.setText("Opens a file");
                        public void mouseExited(MouseEvent me)
                             status.setText("open");
    Thanks
    James

  • Please Help me, How to cut image ?

    I have a image (jpg file). The image is animal, and the image contain 2 basic colours (white is background, black describe animal). I want to cut background around animal
    Please Help me ???
    Please source code .??? Example??

    well it depends what you want to do with this- do you just want to use the black part without a whit contour?
    however if you want to have 2 colors PLEASE save as GIF or as PNG and not as JPG - JPG tends to blur the image a little so your mask will get screwed up with JPG
    the easiest way for me is to do this job in photoshop and save as Tiff then load it with Javax.ImageIO so transparency is kept

  • Please help me(How to allign an Image.)

    I'm using
    StyledDocument document = (StyledDocument) tp.getDocument();
    Style imageStyle = document.addStyle("StyleName", null);
    StyleConstants.setIcon(imageStyle,new ImageIcon("Images\\image1.gif")
    document.insertString(document.getLength(), "ignored text",imageStyle);codes to append an image to JTextPane and
    Style style = document.addStyle("StyleName", null);
    StyleConstants.setForeground(style, new Color(r, g, b));
    document.insertString(document.getLength(), appendMessage, style);
    codes to append text to a JTextPane.
    But when i append both images and texts ,Images are above the text.
    Here I mean the bottom level of Images are at the same level of texes.
    I want to make images below the texes
    How can i do it?
    If you can give me a little exampl
    I think You can understand my requirement.
    If it is difficult to understand tell me.
    please help me

    I'm using
    StyledDocument document = (StyledDocument) tp.getDocument();
    Style imageStyle = document.addStyle("StyleName", null);
    StyleConstants.setIcon(imageStyle,new ImageIcon("Images\\image1.gif")
    document.insertString(document.getLength(), "ignored text",imageStyle);codes to append an image to JTextPane and
    Style style = document.addStyle("StyleName", null);
    StyleConstants.setForeground(style, new Color(r, g, b));
    document.insertString(document.getLength(), appendMessage, style);
    codes to append text to a JTextPane.
    But when i append both images and texts ,Images are above the text.
    Here I mean the bottom level of Images are at the same level of texes.
    I want to make images below the texes
    How can i do it?
    If you can give me a little exampl
    I think You can understand my requirement.
    If it is difficult to understand tell me.
    please help me

  • Please help test a gif program in Lion and Snow Leopard

    Can anyone please help me by testing a Gif creation app on a Lion and Snow Leopard machine?
    The app is called "GIFfun" and is free. It can be downloaded here:  http://www.stone.com/GIFfun/
    I have used this app for years on a Leopard machine, but needed to upgrade this week to Lion.
    Since upgrading to Lion all white areas in Gifs i create are turned to grey and its causing me problems in my workflow.
    I've purchased other Gif creation software to see if the problem was only with that app, but the grey areas are on all Gifs from all Gif creators, which makes me sure the problem lies with Lion.
    It would be a real help for me to know that other Lion users had the same problem, and to know that Snow Leopard users didn't have the problem. (as i would downgrade my OS to Snow Leopard)
    I've attached 3 images to test the app, these images need to be put into a folder and the folder dragged and dropped into the app.
    I need to know if the white areas turn grey on your OS?
    I will be really grateful if anyone can help me with this.
    Thanks
    Dave

    Yes I see your problem.
    Nothing you or I can do about third party software not preforming well in Lion.
    Contact their support:http://www.stone.com/Form.html
    or
    Stone Contact Info
    Tele: 505 345 4800
    Fax: 505 345 3424
    www.stone.com
    [email protected]
    Stone Design Corp
    PO Box 6799
    Albuquerque, NM 87197-6799

  • PLEASE HELP!!! using servlet to generate an image in jsp page

    Hi,
    I am so stuck on this... please help.
    I have a servlet that generated a gif image dynamically. It uses a bean that stores the gif image in a byte array.
    The servlet outputs the byte data to the output stream. The code is really simple and looks like this:
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //HttpSession session = request.getSession();
            try {
                ServletOutputStream stream = response.getOutputStream();
                ImageByteInformation imageByteInfo = (ImageByteInformation) request.getAttribute("imageByteInformation");
                response.setContentType("image/gif");
                response.setContentLength(imageByteInfo.getByteData().length);
                stream.write(imageByteInfo.getByteData(), 0, imageByteInfo.getByteData().length);
                stream.flush();
            }catch( Exception e){   
                System.out.println("You are hooped!: " + e.getMessage() + " " + e.toString());           
            }When I redirect from the dispatch servlet straight to this servlet an image shows up in the browser window.
    However when I try to use this jsp page to display the image nothing happens...
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h2>Hello World!</h2>
            <img src="servlets/Map24ImageDisplayServlet"/>
             //I also tried src/servlets/Map24..., /src/servlets/Map24..., /display, servlets/display
            <h2>Did you see the image?</h2>
        </body>
    </html>My web.xml is here if it helps...
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      <display-name>HelloProject</display-name>
    <servlet>
        <display-name>ServletDispatcher</display-name>
        <servlet-name>ServletDispatcher</servlet-name>
        <servlet-class>servlets.ServletDispatcher</servlet-class>
      </servlet>
      <servlet>
        <display-name>Map24ImageDisplayServlet</display-name>
        <servlet-name>Map24ImageDisplayServlet</servlet-name>
        <servlet-class>servlets.Map24ImageDisplayServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>ServletDispatcher</servlet-name>
        <url-pattern>/hello</url-pattern>
      </servlet-mapping>
      <error-page>
        <error-code>404</error-code>
        <location>/404_error.html</location>
      </error-page>
      <servlet-mapping>
        <servlet-name>Map24ImageDisplayServlet</servlet-name>
        <url-pattern>/display</url-pattern>
      </servlet-mapping>
    </web-app>I can never get an image to come up. In fact I can never get the jsp page to run the servlet at all! HELP!!! What am I doing wrong?
    Thanks
    Edited by: Kind_of_Green on May 5, 2008 3:55 PM
    Edited by: Kind_of_Green on May 5, 2008 4:00 PM

    OK... so you WERE absolutely right about the src path for the image tag.
    However I also had another problem that was quite a bit more insidious and mostly just a symptom
    of how little I know about what goes on under the hood of a web app.
    My bean storing the image info was stored as a request attribute. When the servlet was called from the
    jsp page the request object was either reset or just never initialized. Anyway it is not the same request
    object I assumed it was being passed in the doGet method. I added my bean as a session
    attribute and everything is sparkly :)
    I can only assume that when a request is neither forwarded nor included (as is the case with
    calling the servlet from the img tag) it is disappeared.
    Anyway, thanks a mint man. I so totally appreciate your time.
    Ciao :)

Maybe you are looking for

  • IPod will not install on Windows Vista, iTunes is fine?

    Hello, I am running Windows Vista Ultimate on 2 computers. One computer connects to my 60GB iPod video just fine, while the other looks for drivers and then fails to find any. I get a window that pops up saying "Insert the disc that came with your iP

  • How to use GDP in PCUI ? (CRM 5.0)

    Dear Experts, I would like to use the GDP function in PCUI. I already read about the description in the cook book, but in the customizing application I am not able to choose the right element (GDPL or GDPF). Do you have any suggestion how to use it?

  • PXI 6030e Voltage measurement

    Hello All, I have a PXI 6030E DAQ with a SCB-68 connector board.  I am setting up a simple voltage divider and connecting my Vout to pin 68 on the SCB-68.  My ground is going to pin 67.  My Vin is 5 V DC.  I used DAQ assistant to automatically genera

  • Cannot open my Database

    I have downloaded the Oracle 10g Express Edition and when I try to get to my homepage I am getting page cannot be displayed? I am not all that savvy with this so I don't know the first step in troubleshooting this error. All I know it is going out to

  • Serial Number not suitable for movment

    Dear Friends, while doing PGI through movement type-601 we are getting error message "Stock Data for serial number xxxxx not suitable for movement" please suggest. thanks