I am trying to make a basic Java applet to open a file on the client's computer for them. I would like to call the openFile function in the Java applet below via JavaScript.
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import javax.swing.JApplet;
public class Test extends JApplet {
public void openFile(String filePath) {
File f = new File(filePath);
try {
Desktop.getDesktop().open(f);
} catch (IOException e) {
e.printStackTrace();
}
}
}
In between the body tags of my webpage I have the following:
<applet code="Test.class" height="0" width="0"></applet>
<script type="text/javascript">
document.applets[0].openFile("C:\\test.log");
</script>
When I load the page I get the error:
TypeError: Object # has no method 'openFile'
What do I need to do to fix this error and get the applet working?