Solved

Displaying an image

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 73
Where to store the queries for modification of table 4 55
Java Server Faces parameter pass? 6 39
simple java question 3 44
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now