CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2000
    Posts
    31

    Including Gif files in Java

    Hi,

    I want to create an ImageIcon from a GIF file. I want to include this Gif file in my project so that i don't have to be dependant on an absolute path each time my program runs... since this program would be running in a different PC too...

    Is there a way where in my gif file becomes part of my project and is picked up straight from there...

    Regards,
    Manik


  2. #2
    Join Date
    Mar 2000
    Location
    Dublin, Ireland
    Posts
    124

    Re: Including Gif files in Java

    Manik,

    I've done extensive research and conferring with experts in the field about your particular issue and I have come up with the following answer:

    No.

    If you want your GIF to be part of your project, then keep it in the same directory as your CLASS files OR keep EVERYTHING in a jar file.

    Otherwise, you could go through the trouble of creating a class which holds the bit data of the GIF in a hard-coded fashion and I certainly would not waste my time doing that.

    Barring some complete misunderstanding on my part, I hope this helps.

    Regards,

    dogBear

    PS Please Rate this Response!!!!

  3. #3
    Join Date
    Jul 2000
    Posts
    31

    Re: Including Gif files in Java

    Hi dogBear,

    I have copied the gif file in my class directory, but how do i call it without specifying the entire path of the file...

    eg. new ImageIcon("c:\\class\\xyz.gif");

    instead i want to do something like
    new ImageIcon("xyz.gif")...

    this is not working.... is there any solution to this...

    regards,
    Manik


  4. #4
    Join Date
    Sep 2000
    Location
    Melbourne --> Australia
    Posts
    68

    Re: Including Gif files in Java

    Hi
    Your problem is happening because the current
    directory isnt where your class files are,
    but it is where you compliled the source files.
    One way to solve your problem is to programmatically browse through all of your directories on the system
    untill you locate the directory where you
    placed the file. Then once in the directory
    locate the image file then make a reference
    to it. ie:

    public static File imagefile = new File("your.gif");



    then you can reference this from anywhere
    in the program by importing the class and
    calling

    //where "ClassName" is the name of the class where your image reference is.
    JLabel jl = new JLabel(new ImageIcon(ClassName.imagefile.getAbsolutePath()));



    You can also get that directory name by calling

    ClassName.imagefile.getParent();//returns a String




    Hope this is clear.
    If you need help with this you can
    Email me @
    [email protected]

    Good Luck
    Phill


  5. #5
    Join Date
    Jul 2000
    Posts
    31

    Re: Including Gif files in Java

    Thanks a lot Phill...

    Ur solution was of great help...

    Regards,
    Manik


  6. #6
    Join Date
    Sep 2000
    Location
    Melbourne --> Australia
    Posts
    68

    Re: Including Gif files in Java

    Your welcome !
    Phill.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured