?
Solved

Displaying an image

Posted on 1998-07-21
2
Medium Priority
?
178 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 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