Solved

Displaying an image

Posted on 1998-07-21
2
168 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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bigHeights  challenge 13 55
factorial example challenge 10 60
Python Assistance 7 30
bitbucket vs gitbucket 3 28
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 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

11 Experts available now in Live!

Get 1:1 Help Now