Solved

Displaying an image

Posted on 1998-07-21
2
177 Views
Last Modified: 2012-05-04
Hi there. I have a question very similar to andrewma's.
I'm trying to display an image on the applet, but it keeps
giving me a " Java security error: image is not allowed to
load." error. I'm trying to get around this by using
Toolkit's getImage, but can't seem to display the image.
Any ideas? The code is listed below, any help would be
greatly appreciated. Thanks!

import java.awt.*;
import java.applet.*;
import com.sun.java.swing.*;

public class pic extends JApplet {

  Image image;

  public void init() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    image = toolkit.getImage(getCodeBase().toString()+"save.gif");
  }

  public void paint(Graphics g) {
    if(image != null) {
      System.out.println("displaying image");
      g.drawImage(image,20,20,this);
    }
    else
      System.out.println("Empty image");
  }

  public static void main(String[] args) {
  }
}
0
Comment
Question by:nekobus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
aziz061097 earned 100 total points
ID: 1227357
If you are able to get the image if you run it in appletviewer but you can't get it going in a browser you should sign the applet .

for further information on signing applets go to

http://www.suitable.com/Doc_CodeSigning.shtml
0
 
LVL 6

Expert Comment

by:gadio
ID: 1227358
nekobus, if you are checking the applet locally (loading it in the browser as a file and not as a url) that the reading from the local file system is considered a security violation. I think that this is your problem. What you should do is place your htmls and classes on the server, and check the applet as an http connection (invoke the applet as http://my.server.xxx/aaa/bbb/myapplethtml.html
This should fix the security problem.

0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question