load image in applet

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2006
Posts: 78
Reputation: gampalu is an unknown quantity at this point 
Solved Threads: 0
gampalu gampalu is offline Offline
Junior Poster in Training

load image in applet

 
0
  #1
Oct 11th, 2009
Hi,

I am trying to load an image into an applet, however unsuccessfully.
What's wrong here?

  1. package sess31;
  2.  
  3. // Import the AWT graphics package
  4. import java.awt.*;
  5. import java.applet.*;
  6.  
  7. public class myownapplet extends Applet
  8. {
  9. Image image;
  10. public void init() {
  11. // Load image
  12. //image = getImage(getDocumentBase(), "show14.gif");
  13. }
  14. public void paint(Graphics g) {
  15. // Draw image
  16. g.drawImage(image, 0, 0, this);
  17. }
  18. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 54
Reputation: di2daer is an unknown quantity at this point 
Solved Threads: 12
di2daer's Avatar
di2daer di2daer is offline Offline
Junior Poster in Training
 
1
  #2
Oct 11th, 2009
Hi,

I can't see any faults in your code, so my guess is that the program is unable to find the image.
If your folder structure looks like this:
.\src\sess31\myownapplet.java
then place the image like this:
.\src\image.gif

or specify the location in the path.

Hope this helps!
---------------------------
333 - halfway to hell
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 78
Reputation: gampalu is an unknown quantity at this point 
Solved Threads: 0
gampalu gampalu is offline Offline
Junior Poster in Training
 
0
  #3
Oct 11th, 2009
Thank you for your answer.
At the moment I have the image file in that location but the image is not appearing in the applet.

However if I try with the same image from an URL, it works:
  1. image = getImage(getDocumentBase(), "http://www.iki.rssi.ru/IPL/show14.gif");

I don't get it why is this. Should the image file be in another location?



Originally Posted by di2daer View Post
Hi,

I can't see any faults in your code, so my guess is that the program is unable to find the image.
If your folder structure looks like this:
.\src\sess31\myownapplet.java
then place the image like this:
.\src\image.gif

or specify the location in the path.

Hope this helps!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 54
Reputation: di2daer is an unknown quantity at this point 
Solved Threads: 12
di2daer's Avatar
di2daer di2daer is offline Offline
Junior Poster in Training
 
0
  #4
Oct 11th, 2009
How are you running the applet? Make sure that the image is available from where you run it.
---------------------------
333 - halfway to hell
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 78
Reputation: gampalu is an unknown quantity at this point 
Solved Threads: 0
gampalu gampalu is offline Offline
Junior Poster in Training
 
0
  #5
Oct 11th, 2009
The image is there.
I am attaching the project, so if you could take a look I apreciate very much
Attached Files
File Type: zip Session 31.zip (512.7 KB, 8 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 54
Reputation: di2daer is an unknown quantity at this point 
Solved Threads: 12
di2daer's Avatar
di2daer di2daer is offline Offline
Junior Poster in Training
 
1
  #6
Oct 11th, 2009
Do you get a security exception when launching the applet? If that is the case you need to sign it before you can run it.

If not, it might just be becuase the image doesn't reside in the build folder. Try adding it there.
---------------------------
333 - halfway to hell
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 78
Reputation: gampalu is an unknown quantity at this point 
Solved Threads: 0
gampalu gampalu is offline Offline
Junior Poster in Training
 
0
  #7
Oct 11th, 2009
It works now, thank you very much for the help.
I didn't know that the image had to be in the build folder.

Cheers!

Originally Posted by di2daer View Post
Do you get a security exception when launching the applet? If that is the case you need to sign it before you can run it.

If not, it might just be becuase the image doesn't reside in the build folder. Try adding it there.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 4
Reputation: kizUna_rR is an unknown quantity at this point 
Solved Threads: 0
kizUna_rR kizUna_rR is offline Offline
Newbie Poster
 
0
  #8
11 Days Ago
tq.. this solve my problems =)
Reply With Quote Quick reply to this message  
Reply

Tags
applet, image

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for applet, image
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC