Consider the following code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class wbeswing extends JApplet implements
ActionListener
{
JTextField jtf;
public void init()
{
Container contentPane = getContentPane ();
contentPane.setLayout(new FlowLayout());
ImageIcon mouse = new ImageIcon("mouse.gif");
JButton mjb = new JButton (mouse);
mjb.setActionCommand("mouse");
mjb.addActionListener(this);
contentPane.add(mjb);
jtf = new JTextField(10);
contentPane.add(jtf);
}
public void actionPerformed(ActionEvent ae)
{
String sm="mouse";
String device=ae.getActionCommand();
if(device.equals (sm))
jtf.setText(ae.getActionCommand());
}
}
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
java.security.AccessControlContext.checkPermission(Unknown
Source) at
java.security.AccessController.checkPermission(Unknown
Source) at
java.lang.SecurityManager.checkPermission(Unknown
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?