• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help Needed Urgently!!! -- Showing image

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sharp Tan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic