aspose file tools*
The moose likes Applets and the fly likes Calling applet method in JAR file from Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Calling applet method in JAR file from Javascript" Watch "Calling applet method in JAR file from Javascript" New topic
Author

Calling applet method in JAR file from Javascript

T Almo
Greenhorn

Joined: Sep 09, 2009
Posts: 10
I am trying to call an applet method that resides inside a jar file from Javascript. I am testing this in Firefox, which runs the Embed tag below. If I put my function in the class that runs initially (upload.class) then I can access the function just fine with something like document.uploadAppletFF.myFunction(), but if I put the function in a helper class contained in the jar, I get a function not found error and document.uploadAppletFF.myFunction() no longer works. Do I need some sort of special compilation flag when I create the jar or something? I don't understand why it cant find that function in the helper class. The applet itself runs fine and has no problems using the other classes and methods.

This page (http://java.sun.com/javase/6/docs/technotes/guides/jar/jarGuide.html) leads me to believe that I should have access to the public "helper" class methods as well. "Note that the familiar CODE=myApplet.class parameter must still be present. The CODE parameter, as always, identifies the name of the applet where execution begins. However, the class file for the applet and all of its helper classes are loaded from the JAR file. "



Any ideas would be greatly appreciated.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Welcome to JavaRanch.

For starters, I'd use just the APPLET tag these days, not EMBED or OBJECT. That has no bearing on the problem at hand, though.

The fact that the applet is delivered as a jar file also has no bearing on this.

The thing is, document.uploadAppletFF is a reference to the class that extends (J)Applet, and that's all you get. If you want to call methods in other classes, then you need to channel the call through a method the Applet subclass - you can't call other classes directly, since you don't have a reference to them.


Ping & DNS - my free Android networking tools app
T Almo
Greenhorn

Joined: Sep 09, 2009
Posts: 10
Ah, I see. I didn't realize you only got a reference to the class that extended Applet; thought the jar changed that.

Since my main class instantiates a Thread, which then instantiates another class, I just saved that instantiation to a variable, so that I could reference the other classes (e.g. theThread.theclass.getFunction() ) This works, but when I try to access a variable while my applet is uploading (using the write() function), it seems to block my function call from Javascript. Thats probably a threading issue though.

Thank you.
Tugrul ...
Greenhorn

Joined: Mar 21, 2006
Posts: 3
T Almo, Could you please give a detailed solution.
I have the same problem.
sameer hassan
Greenhorn

Joined: Nov 02, 2009
Posts: 1
Hello Timo

i need to start a .jar file from HTML/JavaScript on click of a button ..
can you please tell me how can i do it.....

Regards
Sameer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling applet method in JAR file from Javascript