Results 1 to 3 of 3
  1. #1
    shadowfax57 is offline Member
    Join Date
    Aug 2010
    Rep Power

    Default Image File Location


    I'm sorry if this is in the wrong section. It deals with an Applet (which theres a separate section for), but is also incredibly basic. Since even most of the post titles in the "New to Java" section went over my head (lol), I figured I was better off posting in here.

    I recently taught myself some basics over the summer for a course I'm going to take this fall. In doing so, I tried making some applets containing images. I tried this several times using a line similar to below.

    Image img = getImage( getCodeBase(), "Filename");

    This didn't exactly work out for me; I think the problem is that the program can't find the file I'm referencing. The book I read didn't give too much info on where to save the actual image file I was referencing, or what getCodeBase did

    What's the best way to bring in an image file like this?

    Thanks for your time.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Destiny Islands
    Rep Power


    When in doubt, print it out:
    Java Code:
    That should give you some idea of where getCodeBase is pointing. Now you can look at where your file is and adjust the path appropriately.

    Much luck to ya.

    PS: getImage appears to be the proper code for you to use here. Just keep in mind to check out what the code base is, where the file is, and how they relate to one another.

  3. #3
    shadowfax57 is offline Member
    Join Date
    Aug 2010
    Rep Power


    Thanks. Haha I'm a bit embarassed I didn't think of such a simple solution, but it worked well.

Similar Threads

  1. Specify full location of txt file
    By Dekkon0 in forum New To Java
    Replies: 4
    Last Post: 05-15-2010, 05:17 AM
  2. need to copy file from one location to another location
    By naveen.dpt2007 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 03:53 PM
  3. how to specify location of file to be uploaded?
    By anthrax in forum New To Java
    Replies: 11
    Last Post: 01-13-2010, 02:48 PM
  4. File Location
    By bcbird in forum New To Java
    Replies: 1
    Last Post: 09-17-2009, 08:03 AM
  5. Applet Image location
    By MarkWilson in forum NetBeans
    Replies: 3
    Last Post: 06-30-2008, 07:37 AM

Posting Permissions

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