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
Solved

Displaying an image

Posted on 1998-07-21
2
175 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
print map entry 34 72
ejb example issues 3 26
What browser will run Java? 7 62
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

839 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