This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help Needed Urgently!!! -- Showing image" Watch "Help Needed Urgently!!! -- Showing image" New topic
Author

Help Needed Urgently!!! -- Showing image

Sharp Tan
Greenhorn

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,
Sharp
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


- Daniel
Sharp Tan
Greenhorn

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;
import java.net.*;
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("http://java.sun.com/images/logos/javalogo52x88.gif");
image = this.getImage(url);
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
public void start() {
addItem("starting... ");
}
public void stop() {
addItem("stopping... ");
}
public void destroy() {
addItem("preparing for unloading...");
}
void addItem(String newWord) {
System.out.println(newWord);
buffer.append(newWord);
repaint();
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
}
}
Regards,
Sharp
Nathan Pruett
Bartender

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... ).

-Nate


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

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!
Sharp
 
Don't get me started about those stupid light bulbs.
 
subject: Help Needed Urgently!!! -- Showing image