--
-Greg
--
-Greg
public void init()
{
ImageIcon aTLHS = new ImageIcon("aTLHS.gif");
this.applyToLeftHandSide = new JButton(aTLHS);
this.add(this.applyToLeftHandSide);
} // ends init(void)
java.security.AccessControlException: access denied
(java.io.FilePermission aTLH.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 SolveLinearProblemApplet.init(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Greg Faron wrote:
>
> Has anyone come across a FilePermission problem when trying to
> instantiate a simple JButton with an ImageIcon in an applet? I have
> a GIF in the same directory as the applet class (no JARs here) and
> it's wide open read permissions (-rw-rw-r--). From the init method
> below, I receive the error further below. I didn't get this when
> working with an application...
>
> --
> -Greg
>
> public void init()
> {
> ImageIcon aTLHS = new ImageIcon("aTLHS.gif");
This statement says to get aTLHS.gif from the current
directory of the local file system. No wonder you get
a file permission error.
To get a file off the server you have to use a URL and
get an InputStream.
--
WBB - wbro...@lanw.com
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP
ISBN 0-7821-2809-2
I've also tried the following code, but it gave me the same
FilePermission error message. Any ideas?
Greg
public void init()
{
URL url = null;
try
{ url = new URL(getCodeBase() + "/aTLHS.gif"); }
catch(MalformedURLException e)
{ System.err.println("failed"); }
ImageIcon aTLHS = new ImageIcon(url);
} // ends init(void)
Furthermore, my earlier post was a direct derivation from the samples
given at Sun
<http://developer.java.sun.com/developer/codesamples/javax.swing/234.html>
Sun:
ImageIcon icon = new ImageIcon("image.gif");
JButton button = new JButton(icon);
William Brogden wrote: