0

I've placed the image TestIcon.png in the src folder of a Java applet (the directory is C:\Users\User\workspace\applettest2\src\TestIcon.png). Everything I've read says that I should be able to use the image simply by referencing "TestIcon.png". Example:

ImageIcon xIcon = new ImageIcon("TestIcon.png");

Howerver, running the applet in Eclipse with this code doesn't work; the image is not displayed. If I type out the image's entire path:

ImageIcon xIcon = new ImageIcon("C:\\Users\\User\\workspace\\applettest2\\src\\TestIcon.png");

then the applet displays the image properly. Isn't the default path for resources supposed to be in the "src" folder? Thanks.

1 Answers1

1

If you are running it inside the Applet then try with Applet#getCodeBase() and Applet#getDocumentBase

Image image = getImage(getDocumentBase(), "TestIcon.png");

Find more samples Here and Here

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76