File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Help Needed Urgently!!! -- Showing image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help Needed Urgently!!! -- Showing image" Watch "Help Needed Urgently!!! -- Showing image" New topic

Help Needed Urgently!!! -- Showing image

Sharp Tan

Joined: Aug 16, 2001
Posts: 6
Hi folks,
I try to show a image from other web site in my applet. Is it possible? If it is possible, pls kindly give me a sample code! I'm very appreciate for your help.
Thanks and Best Regards,
Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
If you have the exact URL of the image, use:

Where "url" is the location of the image, either as a URL object or a string (i think...).
Of course, that method only works within a subclass of Applet or JApplet.
Hope that helps.

- Daniel
Sharp Tan

Joined: Aug 16, 2001
Posts: 6
Hi Daniel,
Thanks for your response!
Fowllowing is my applet source: If the image from the same domain as the applet, it works. If not, no error on image. Would you mind tell why? Thanks again.
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JApplet;
public class Simple extends Applet {
StringBuffer buffer;
Image image;
public void init() {
buffer = new StringBuffer();
addItem("initializing... ");
try {
// image = tk.getImage(new URL("http://localip:8080/Radiation/images/radiation/GR1620B.jpg"));
URL url = new URL("");
image = this.getImage(url);
} catch(Exception e) {
public void start() {
addItem("starting... ");
public void stop() {
addItem("stopping... ");
public void destroy() {
addItem("preparing for unloading...");
void addItem(String newWord) {
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Actually, I think that may be part of the "applet sandbox"... an applet can't access any other domain than the server it's coming from... I think not being able to load an image from another server is kinda taking the sandbox approach a little too far, but, hey, reading images from a different server is even bad practice in HTML ( especially if the images are not yours... ).


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Sharp Tan

Joined: Aug 16, 2001
Posts: 6
Hi Nathan,
Thanks for your response.
For my project, I do need to read and proccess the image. I do have the right to use the image. My problem is I need do these jobs online. So, have any solution to solve it?
By the way, anybody has experience to signe an Applet? I mean allowing a server other than the one applet's from trusts the applet.
Thank you very much for your help!
I agree. Here's the link:
subject: Help Needed Urgently!!! -- Showing image
It's not a secret anymore!