Friday, 13 September 2013

Java applet functions aren't being accessed by Javascript

Java applet functions aren't being accessed by Javascript

I am trying to create a very simple java Applet to try out using Java
functions in a web browser. problem is, is that I can't get any sort of
functionality from my applet. I've tried dozens of tutorials and answers
from within this site, but nothing produces any different result, The
browser always says AppName.FunctionName is not a function.
Here is my html...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4 /strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Test Applet</title>
</head>
<body onload="test()">
<applet code="TestApplet.class" name="AppTest"
height="350" width="100"></applet>
<script language="Javascript">
function test(){
alert("Attempt 1");
var elem= document.getElementById('AppTest');
alert(elem);
elem.test();
alert("Attempt 2");
document.AppTest.test();
}
</script><br>
</body>
</html>
and here is my Java code...
import javax.swing.JApplet;
public class TestApplet extends JApplet {
public String sayHi(){
return "hello";
}
public void test(){
System.out.println("You did it bro");
}
}
Any ideas why this seems to do nothing? Note: I am testing it using FireFox

No comments:

Post a Comment