Security Permission errors with ImageIcon, Please Help!

I have an applet that uses some ImageIcons. When I had the .GIF files stored on my computer, I got a security error because an applet cannot look at the user's hard drive. Then I tried to make a policy file that let gave the applet permission to look at my hard drive (that was a huge pain in the ***!) and it didn't work. Then I uploaded the GIFs to my website and I still got security errors. Here's what the errors were:

java.security.AccessControlException: access denied (java.net.SocketPermission www.angelfire.com resolve)

at java.security.AccessController.checkPermission(AccessCOntroller.java:401)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)

at java.lang.SecurityManager.checkConnec(SecurityManager.java:1042)

and the list goes on... because of my ImageIcon.<init>(ImageIcon.java:119)

If anyone knows how to fix this problem OR how to make a PolicyTool file that will give my applet permission to Load/Save charachters on the user's hard drive, please help.

Thanks,

Eric

[1071 byte] By [RedViking] at [2007-9-27 20:12:23]
# 1
will if you put your applet and your imageicon in the same folder or dirc you should not have this prob and you will not need to sign the applet
buddyjoe at 2007-7-7 0:20:19 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

I tried that, but it still didn't work (when it was saved on my computer), I guess I could just upload the whole thing but that would be a pain... Besides, I'm gonna have to get the thing signed anyway, so I have a few questions about that:

1.From what I understand, To give an applet permission to read/write on your hard drive, you need to use policytool.exe to make a policy file and then save it in a certain place where the JRE will look for it. I don't know where that place is, or if anything I have said made any sense, so please help me if you can.

2.Also, couldn't I use the Java to Javascript thing to save the charachter in a cookie file? Is that hard?

Thanks,

Eric

RedViking at 2007-7-7 0:20:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
Help!
RedViking at 2007-7-7 0:20:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
Did you try using the actual name of the gif and tell the compiler where exactly it is located?
kuyalfinator at 2007-7-7 0:20:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5

The solution is to use an Image rather than an ImageIcon. Then use the getImage method with getCodeBase() as the first parameter, not getDocumentBase(). This worked for us:

public class UsingIcons extends JApplet

{

Image imagOneWay ;

public void init()

{

resize(300,300);

}

public void paint(Graphics g)

{

g.drawString( getCodeBase().toString() + "1waya.gif", 50, 90 ) ;

g.drawString( getDocumentBase().toString() + "1waya.gif", 50, 110 ) ;

imagOneWay = getImage( getCodeBase(), "1waya.gif" ) ;

g.drawImage( imagOneWay, 50, 200, this ) ;

}

}

Jesse Heines

heines@cs.uml.edu

heinesj at 2007-7-7 0:20:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...