Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Error while opening a JApplet in web-browser

  Asked By: Darla    Date: Dec 09    Category: Java    Views: 673

Consider the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class wbeswing extends JApplet implements

JTextField jtf;

public void init()
Container contentPane = getContentPane ();
contentPane.setLayout(new FlowLayout());

ImageIcon mouse = new ImageIcon("mouse.gif");
JButton mjb = new JButton (mouse);


jtf = new JTextField(10);


public void actionPerformed(ActionEvent ae)
String sm="mouse";

String device=ae.getActionCommand();

if(device.equals (sm))


However the above code gives the following errors in
the java Console while opening it in the web-browser:

java.security.AccessControlException: access denied
(java.io.FilePermission mouse.gif read) at
Source) at
Source) at
Source) at java.lang.SecurityManager.checkRead(Unknown
Source) at sun.awt.SunToolkit.getImageFromHash(Unknown
Source) at sun.awt.SunToolkit.getImage(Unknown Source)
at javax.swing.ImageIcon.<init>(Unknown Source) at
javax.swing.ImageIcon.<init>(Unknown Source) at
wbeswing.init(wbeswing.java:17) at
sun.applet.AppletPanel.run(Unknown Source) at
java.lang.Thread.run(Unknown Source)

What could be the cause of the problem?



3 Answers Found

Answer #1    Answered By: Timothy Patterson     Answered On: Dec 09

Dont you try to get an image from your hdd without a signed applet?

Answer #2    Answered By: Jezza Brown     Answered On: Dec 09

Can't you try specifying the path of the gif  file specifically.
If you don't want to sign your applet, you can send the gif file packaged
in the jar in which you are shipping your applet.
Then it WILL work.

Answer #3    Answered By: Norman Ray     Answered On: Dec 09

i think this ^^ is the line that causes the error.
try Imagelcon mouse  = new Imagelcon(getCodeBase() , "mouse.gif");

Didn't find what you were looking for? Find more on Error while opening a JApplet in web-browser Or get search suggestion and latest updates.