wood burning stoves
The moose likes Applets and the fly likes Adding Images to JApplet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Adding Images to JApplet" Watch "Adding Images to JApplet" New topic

Adding Images to JApplet

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
I want to pass in the following :
1) number of types of entities (i.e. men, women, girls, etc..,)
2) for each entity I want to supply the count of each (i.e. 5 men, 3 women, etc..,)
3) for each entity I want to supply an image name (i.e. using getCodeBase I want to tack on another directory called images and then under that I have some images corresponding to this field)

So an example of param tag values would be :
1) entityCount=2
2) entity1=5 (for men), entity2=3 (for women)
3) entityImg1=men.jpg, entityImg2=women.jpg

I want to be able to use locate the images and place them within the JApplet in order so that, in this case, men.jpg and women.jpg are placed in the Japplet in order. What's the best way of accomplishing this? Thanks for and appreciate any useful code approach for handling this.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
Maybe some additional info might be helpful.
Here's my directory structure (mapped to another server) :

My JApplet class (i.e. ObjTableDisp.class) is in the above directory and is part of the diagram package (the directory diagram above).

I have a .html file underneath the dir2 directory and the applet tag looks as such :
<applet name="japp" width="600" height="600" codebase="P:/Inetpub/wwwroot/dir1/dir2/" code="diagram.ObjTableDisp.class">

I have a directory under dir2 called images and underneath that I have a jpg (i.e. apple.jpg).

I go into dir2 in commandline and type the following :
P:\Inetpub\wwwroot\dir1\dir2>appletviewer -J-Djava.security.policy=P:/Temp/ObjTa
bleDisp Test3.html

I wasn't sure so I tried creating a policy file since I keep getting file permission errors. The error when running is :
Stack Traceaccess denied (java.io.FilePermission file:/P:/Inetpub/wwwroot/dir1/dir2/images/apple.jpg read)

Here's the policy file I created :
/* AUTOMATICALLY GENERATED ON Tue Oct 11 14:24:29 EDT 2011*/
grant codeBase "file://P:/Inetpub/wwwroot/dir1/dir2/images/" {
permission java.io.FilePermission "apple.jpg", "read";

grant codeBase "/dir1/dir2/" {
permission java.io.FilePermission "apple.jpg", "read";

Is there anything that stands out here that I'm doing wrong? I tried various approaches and none worked so this is at the end of trying numerous things out. Would appreciate some help on this as I have no idea where exactly I'm going wrong. Thanks.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

What are you doing wrong? You forgot that the applet runs in a browser on the client machine, not on your server. You'll have to provide a proper URL for your "codebase" attribute, not a file path.

Don't waste your time mucking about with policy files, getting them installed on other people's machines isn't worth the trouble. On the other hand if you don't ever intend to run this applet on somebody else's machine, then don't waste your time making it an applet. Just make it an application.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
Not sure what I'm missing. Yes the app is on the server but I'm not referring to the server by name or IP but everywhere by drive. Appletviewer is opening the page while I'm in the directory on the mapped drive and I've tried using the direct path to the mapped drive in the codebase property as well. Shouldn't it be okay doing it this way? Treating everything as though localhost? Appreciate the response. Thanks again.

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
Maybe I should add this as well. I have an JApplet that needs to be passed a parameter (will be one of maybe 1000 picture names). The application needs to load the picture(s) - could be more than one - and display them in a table. What way would you accomplish this? The pictures are stored on the server - not sure if it's easier (worth) saving in a separate directory than the JApplet (I would rather to keep separate) or storing everything in a jar. I'm open to suggestions as this is just something I started out trying. Thanks again.
I agree. Here's the link: http://aspose.com/file-tools
subject: Adding Images to JApplet
It's not a secret anymore!