Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet permissions trouble

 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried to get imageIcons to work in my applet and when i get it to actually look for the images, it does not load the applet at all and comes up with a load of spiel about the permission of the files being wrong.

I have changed all of the permissions to rw and have tried creating fresh images, yet alas, it does not allow the images to load, if it looks for them.

Please help any one.

Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are the images located - in the same directory as the applet? How do you access them? Applets can't normally use the java.io package, if that's the method you use.
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the images are in a folder inside the folder that the Animator.java is in, but i have used the extension "Images//N1.gif" N1 being the name of the image. I have already used images in the applet and had no problem with it, but now it seems to be throwing a paddy at me.

code for image :
noteImages = new Image[32];
for(int k=0; k<32; k++){
noteImages[k] = animator.getImage(animator.getCodeBase(), "Images/N1.GIF");
}

using paint method as follows:


public void paint(Graphics g){//201
super.paint(g);
g.drawImage(noteImages[0],60,95,this);
}//201


at this very moment it compiles with out putting any images where i want them, but it simply wont show the images.
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while i'm on it, i have tried the imageIcons as well with very similar results. Also have tried it on many different computers.

Thanks

Andy
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apoliogies to everyone for my lack of using a single post to get my point accross, i'm new to all this.

The exact error that i'm getting is :

java.security.AccessControlException: access denied(java.io.FilePermission Images//N1.gif read).

Any ideas.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applets can't access the java.io package due to security restrictions, although there are a couple of workarounds. You must be using the applet off your local hard disk (which makes the first parameter to getImage a file URL instead of an http URL; if instead you ran it from a server (even a local one) it should work fine.

By the way, you can edit previous posts by clicking the little paper-and-pencil icon located above the message.
 
Mohammad Farhat
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Andrew,
you need to have the applet signed, and you probably would need to set appropriate permissions (security permissions) on the client's machine in order to be able to have complete access to the file system of the client.
As far as signing the applet, this is a "somewhat" simple task that you can look for online (many links exist).
As for setting security permissions, you can do that by modifying the security file located at C:\Documents and Settings\<USERNAME>\Application Data\sun\Java\Deployment\security\java.policy to only contain:
grant { permission java.security.AllPermission; };
this will give complete access to applets
Best,
Mohammad
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried looking in this file, but alas, when i get to security it doesn't have any folders or files in it?

will this affect it or not?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my JDK installations the java.policy file is in lib\security and jre\lib\security, respectively, inside the JDK installation directory (and there is no C:\Documents and Settings\<USERNAME>\Application Data\sun). So it seems that you may need to hunt around a bit for it.
[ April 13, 2006: Message edited by: Ulf Dittmer ]
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have found the java.policy file and it states that :


grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};

(plus alot of other stuff after this)

do i now have to change this? does the file have to only contain what was previously posted as there is also alot of other stuff in the file, which i am dubious of deleting.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you shouldn't change or remove any of the stuff in there. You can add to it to grant privileges to applets; this is outlined at the end of this wiki article. Just change the URL to "http://localhost:8080/" or "file:///-" (not sure about the syntax for "file").
[ April 13, 2006: Message edited by: Ulf Dittmer ]
 
Mohammad Farhat
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you were unable to find the file (or even the directory) i pointed out, then you will need to change the appropriate java.policy file of your current jre installation (this can be found under jre\lib\security\java.policy). The file i pointed out with the c:\documents and settings\<USERNAME>... is the default one for ll jre used in the system.
Ofcourse
As for as to what to modify the java.policy file to, i have really tried many things before, and the only thing that worked for me was setting what i mentioned eariler, "grant { permission java.security.AllPermission; };"
this would allow the applet to have full control over you system.
Best,
Mohammad
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have got in my java.policy file the following:
grant codeBase "file:${{java.ext.dirs}}/*" {
permission java.security.AllPermission;
};

is this the problem?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure about the double brackets syntax, but this would only work if the class files were in the java.ext.dirs directory, which -for an applet you download from a web site- they wouldn't be.
 
Andrew Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried to do this policy thing and it stops the exception, i have also tried running it through a local server, which also gets rid of the exception that i am still getting when i compile and run on my machine.

This still doesn't display the images though. i don't understand why this is refusing to work as i have created the JLabel, put an image icon on the JLabel, set the bounds, set it to be visible, and added it to a JPanel. I think that it should be working, but it simply doesn't show the image.

Any more suggestions as i'm losing hope.

Thanks for your continued help. You're all legends.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can post a minimal example of code that exhibits the problem - just one panel, one image etc. - so we can look at it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic