Skip to main content

images not loaded.....

3 replies [Last post]
bugthefixer
Offline
Joined: 2006-02-17

1156.1

i am accessing the applet resieding on the linux server...i am accessing mysql database as well...what is happening is that every things loads properly except for the image.....i have tried to change the extensions from Gif to png and jpg but nothing seems to work...how can i load these images....because on my local computer running windows every thing works fine...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous

Hi,

Do you have this problem while creating your code, or once compressed in a JAR archive ?

If you are in the first case, post some examples of your code, and use relative paths, not absolute ones.

If you are in the seconde one, well, we are in the same pinch...

Actually, my applications loads the images very well, but once I make my .jar archive, even if the images are in the right directory of the archive, they just doesn't show up...

Anonymous

Well, I've read here and there that, in a Jar file, you HAVE to use URLs to load images, and when I do so, it never loads my image, even not in the jar version......

see below :

[code]
String dot = "No";
if(i == decimals)dot = "";
try{
URL digitPic;
switch(digit){
case 0: digitPic = new URL("/images/zero"+dot+"Dot.png");break;
case 1: digitPic = new URL("/images/one"+dot+"Dot.png");break;
case 2: digitPic = new URL("/images/two"+dot+"Dot.png");break;
case 3: digitPic = new URL("/images/three"+dot+"Dot.png");break;
case 4: digitPic = new URL("/images/four"+dot+"Dot.png");break;
case 5: digitPic = new URL("/images/five"+dot+"Dot.png");break;
case 6: digitPic = new URL("/images/six"+dot+"Dot.png");break;
case 7: digitPic = new URL("/images/seven"+dot+"Dot.png");break;
case 8: digitPic = new URL("/images/eight"+dot+"Dot.png");break;
case 9: digitPic = new URL("/images/nine"+dot+"Dot.png");break;
default: digitPic = new URL("/images/baseDigit.png");break;
}
ImageIcon img = new ImageIcon(digitPic);
label = new JLabel(img);
c.gridx = size-i;
c.gridy = 0;
this.add(label,c);
}catch(MalformedURLException e){System.out.println("Error loading image file.");}

[/code]

---------------------------------------------------------
It used to work when i used the [code]ImageIcon[/code] constructor instead of the [code]URL[/code] one (with all the modifications on the rest of the code it implies)

Anonymous

Ok, i solved it,

I used [code] new ImageIcon(this.getClass().getResource("images/zero"+dot+"Dot.png"));
[/code]
instead, and everything went nice