This is literally my first question about Java, so bear with me.
I built a stupid simple applet class called HelloWorldApp.class from this code:
import java.applet.Applet;
class HelloWorldApp extends Applet
{
static final long serialVersionUID = 6636669702238171717L;
public String test()
{
return "Hello World!"; // Display the string.
}
}
I then built a jar file from said class file. Afterwards, I made a stupid simple JNLP file:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="/Content/applets" href="/Content/applets/datadelivery.jnlp">
<information>
<title>Hello World</title>
<vendor>Me</vendor>
</information>
<resources>
<!-- Application Resources -->
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="HelloWorldApp.jar" main="true" />
</resources>
<applet-desc
name="Test Applet"
main-class="HelloWorldApp"
width="300"
height="50">
</applet-desc>
<update check="background"/>
</jnlp>
I tossed all three items in the directory /Content/applets. Finally, to tie it all together, I dropped this in the body of an HTML document:
<script type="text/javascript">
var attributes = {
id:'deliveryApplet',
code: 'HelloWorldApp',
// note: I tried including "codebase: '/Content/applets'", but nothing new happened
width: 300,
height: 50
};
var parameters = {
jnlp_href: '/Content/applets/datadelivery.jnlp'
};
deployJava.runApplet(attributes, parameters, '1.6');
</script>
...and created a button with an onclick action of calling:
alert(deliveryApplet.test())
The problem? No function call; the JS console responds saying "Uncaught TypeError: Object # has no method 'test'". So somewhere along the line, deployment didn't work out. But where? Based on examples the JNLP stuff looks right.
alert(deliveryApplet.test())
is a very naive way to get access to an element in the page. I suggest you write a JSfunction
that accepts a string for the ID and returns the appropriate element. Test it thoroughly across a range of browsers. In the applet, call the (tested and robust) JS function. Also, make sure the applet invocation declaresscriptable=true
. – Contaminatealert(deliveryApplet.test())
from Safari. I had to usealert(document.applets[0].test())
for firefox, though! – Economicallydocument.getElementById('deliveryApplet')
– Economically