944,101 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 3332
  • Java RSS
Oct 11th, 2009
0

load image in applet

Expand Post »
Hi,

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

Java Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 21
Solved Threads: 0
Junior Poster in Training
gampalu is offline Offline
78 posts
since Mar 2006
Oct 11th, 2009
1
Re: load image in applet
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!
Reputation Points: 22
Solved Threads: 13
Junior Poster in Training
di2daer is offline Offline
66 posts
since Sep 2008
Oct 11th, 2009
0
Re: load image in applet
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:
Java Syntax (Toggle Plain Text)
  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?



Click to Expand / Collapse  Quote originally posted by di2daer ...
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!
Reputation Points: 21
Solved Threads: 0
Junior Poster in Training
gampalu is offline Offline
78 posts
since Mar 2006
Oct 11th, 2009
0
Re: load image in applet
How are you running the applet? Make sure that the image is available from where you run it.
Reputation Points: 22
Solved Threads: 13
Junior Poster in Training
di2daer is offline Offline
66 posts
since Sep 2008
Oct 11th, 2009
0
Re: load image in applet
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, 108 views)
Reputation Points: 21
Solved Threads: 0
Junior Poster in Training
gampalu is offline Offline
78 posts
since Mar 2006
Oct 11th, 2009
1
Re: load image in applet
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.
Reputation Points: 22
Solved Threads: 13
Junior Poster in Training
di2daer is offline Offline
66 posts
since Sep 2008
Oct 11th, 2009
0
Re: load image in applet
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!

Click to Expand / Collapse  Quote originally posted by di2daer ...
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.
Reputation Points: 21
Solved Threads: 0
Junior Poster in Training
gampalu is offline Offline
78 posts
since Mar 2006
Dec 7th, 2009
0
Re: load image in applet
tq.. this solve my problems =)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kizUna_rR is offline Offline
4 posts
since May 2009
Jul 9th, 2010
0
Re: load image in applet
You can Run this program.First copy it in jdk/bin directory then copy rn1.jpg named any picture in ur jdk/bin directory. Ok Run this program now

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;

public class ronyphoto1 extends Applet
{
Image Img1;


public void init()
{
URL codebase=getCodeBase();

showStatus(codebase.toString());

Img1=getImage(codebase,"rn1.jpg");
//Img2=getImage(codebase,"Image2.gif");
}


public void paint(Graphics g)
{
g.drawImage(Img1,10,10,this);
//g.drawImage(Img2,400,10,this);
}

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Alimuzzaman is offline Offline
1 posts
since Jul 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: information added to flash screen
Next Thread in Java Forum Timeline: can i compile a java pgm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC