Reputation: 841
Every time I call a function of my applet from my Java Script, it throws an undefined exception. And my googling hasn't helped me at all.
here is a link to the site I am am hosting it on right now: Host Site
Here is my html for the embedding the Applet:
<object type="application/x-java-applet"
id="ClientApp" name="ClientApp"
archive="Cal.jar"
width="100" height="100">
<param name="code" value="Calendar_Algorithm" />
<param name="mayscript" value="true" />
</object>
And here is my java script code:
function test(){
document.writeln("<p> "+"Test"+" </p>");
try{
var s=document.ClientApp.getGreeting();
document.writeln("<p> First: "+s+" </p>");
}catch(err){
document.writeln("<p>Error Caught 1: "+err.description+"</p>");
}
try{
var s=document.getElementById('ClientApp').getGreeting();
document.writeln("<p> Second: "+s+" </p>");
}catch(err){
document.writeln("<p>Error Caught 2: "+err.description+"</p>");
}
document.close();
}
I know it loads the applet because I can see the gui, and if it helps here is my init function
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel(getGreeting());
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
here is a link to my full code as well Code
I got a feeling that the error is incredibly obvious, but I just can not see it.
Any help would be great!
P.S. The Applet class files are now in a signed jar file.
Also This will be placed in the webapps folder of a tomcat server, but I am currently accessing it as a local file.
Upvotes: 2
Views: 6390
Reputation: 182
From http://www.w3.org/TR/html401/struct/objects.html#h-13.4, about the object attribute:
"This attribute names a resource containing a serialized representation of an applet's state." I predict this is not what you intended.
In addition, if you're on firefox mac you need the mayscript param for (JS-2-Java interaction) LiveConnect to work.
A way to deploy applets that works:
<object type="application/x-java-applet" width="100" height="100">
<param name="codebase" value="/applet_dir" />
<param name="code" value="Calendar_Algorithm" />
<param name="mayscript" value="true" />
</applet>
If you don't have the Java console enabled you should definitely do so. It's enabled under the Java Control Panel advanced settings.
By the way, in Chrome Linux it works! In Firefox Linux it doesn't. Firefox doesn't like that both object and code param is specified and that the class names are different.
LiveConnect is buggy, especially on the mac. For an overview have a look at: applets-missing-information-about-liveconnect-and-deployment Basically you need to know what parts of LiveConnect to use and which not to.
Upvotes: 3