aspose file tools*
The moose likes Applets and the fly likes Where should I put the applet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Where should I put the applet?" Watch "Where should I put the applet?" New topic
Author

Where should I put the applet?

Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
I have a Graph.java which extends JApplet, and import a java_c.Caller.java which will call a dll in my pc.
Make it clear:
Graph.java extends JApplet,and calls Caller.java
Caller.java calls a dll in my pc.

I want to put them in the Tomcat\webapps\myapp, how shoul I do?
Thanks!!!


SCJP1.4 93%<br />SCWCD��
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
You'd put the class files along with the HTML file that contains the applet tag into ...\myapp. I'm not sure where the DLL needs to go on a Windows machine, probably into a directory that's part of PATH.

In any case, you need to allow the applet to use native libraries. The two methods for doing that are described here.
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
Originally posted by Ulf Dittmer:
You'd put the class files along with the HTML file that contains the applet tag into ...\myapp. I'm not sure where the DLL needs to go on a Windows machine, probably into a directory that's part of PATH.

In any case, you need to allow the applet to use native libraries. The two methods for doing that are described here.


Thanks!!But I think the dll file is on my pc, so is in the host, why should I sign the applet.In fact my applet can run on the appletviewer and cannot on the ie or firefox?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
Because applets have security restrictions in what they are allowed to do. Accessing native libraries is one of the things they can't do. Appletviewer does not generally enforce these restrictions, but browsers do.
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
Originally posted by Ulf Dittmer:
Because applets have security restrictions in what they are allowed to do. Accessing native libraries is one of the things they can't do. Appletviewer does not generally enforce these restrictions, but browsers do.


Thank for your answer!!!
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
Another question:
I have resolve the problem dll.I make a jar file including the applet、the Caller(call the dll)and 3 images.The applet should read the images,one is the background, others are button's icons.But why in the browser,the images can't be read?
My step:
1、Make the applet、Caller.java(it's in the java_c package),the images together into applet.jar.
2、Ues the commands:
keytool -genkey -keystore kidd.store -alias kidd
keytool -export -keystore kidd.store -alias kidd -file kiddr.cert
jarsigner -keystore kidd.store applet.jar kidd
3、Create a applet.policy file,with the following content:
keystore "file:E: /javacode/kidd.store", "JKS";
  grant signedBy "kidd"
  { permission java.io.FilePermission }
4、add a line in the ${java.home}/jre/lib/security/java.security:
policy.url.3=file:E: /javacode/applet.policy
Now I can run applet in the browser,but it still can't show the 3 images,why?


One more question:
I want to move the applet.jar in the ${Tomcat.home}/webapps/myapp, I think it mustnot under the ../myapp/WEB-INF, because the applet will be downloaded.But the applet.jar has included the java_c package(Caller.java in it),I want to make the java_c package move from applet.jar to the ../WEB-INF/classes. How can I do?Can the applet in the jar call a class in the WEB-INF/classes?How should I change my code?

Really Thanks!!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
If the images are inside of the jar file, then the browser can't access them - only the applet can read them. If you want to use them in HTML as well, then you need to keep them outside of the jar file.

Applet classes can't be anywhere inside of WEB-INF, because that directory is not publicly accessible.
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
Originally posted by Ulf Dittmer:
If the images are inside of the jar file, then the browser can't access them - only the applet can read them. If you want to use them in HTML as well, then you need to keep them outside of the jar file.

Applet classes can't be anywhere inside of WEB-INF, because that directory is not publicly accessible.


Yes, thanks for your reply.But the first question is "I put the images in the jar, I want them to be read by applet and be showed. One is applet' backgroud ,others are button's Icon. So I think in the browser ,them should be read by applet not html. But in fact, them didn't appear, on the other hand them appeared in the AppletViewer. So I'm puzzled "
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
I see - by "in the browser" I thought you meant as opposed to "in the applet". But you meant as opposed to "in appletviewer".

What code are you using to access the images? Are there any exceptions?
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
Originally posted by Ulf Dittmer:
I see - by "in the browser" I thought you meant as opposed to "in the applet". But you meant as opposed to "in appletviewer".

What code are you using to access the images? Are there any exceptions?


I'll make my questions clearer next time.
The code to read the backgroud image is


The code of the buttons is:


When the applet is running in FireFox, the console print the exception is:

There aren't any exceptions of the buttons' images. But all the 3 images didn't appear.Please tell me why?Thanks!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
File f = new File("main.jpg");
img = ImageIO.read(f);


This only works for images in the local file system, not for images that are in the applet jar file, or in the same web directory. Resources in the jar file can be accessed as described here. Files in the web directory can be accessed through HTTP with the HttpUrlConnection class.

As to the image icons, are the images on the top level of the jar file, i.e. not in a directory?
[ January 10, 2007: Message edited by: Ulf Dittmer ]
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
Thanks !
Following your reply, I made the backgroud image shown in the Firefox.

The two Icons are on the top level of the jar file.What can I do with them?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
Here is some code that pulls an image out of a jar file for use as a label:


[ January 10, 2007: Message edited by: Ulf Dittmer ]
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65

You are a nice man!!!Really really thank you!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where should I put the applet?