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
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
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
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.
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
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, the permaculture playing cards