title: How to call a method declared in an applet from JavaScript
body: <p>I am trying to make a basic <a href="https://en.wikipedia.org/wiki/Java_applet" rel="nofollow noreferrer">Java applet</a> 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.</p>
  <pre><code>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();
          }
      }
  }
  </code></pre>
  <p>In between the body tags of my webpage I have the following:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;applet code=&quot;Test.class&quot; height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;/applet&gt;
  
  &lt;script type=&quot;text/javascript&quot;&gt;
      document.applets[0].openFile(&quot;C:\\test.log&quot;);
  &lt;/script&gt;
  </code></pre>
  <p>When I load the page I get the error:</p>
  <blockquote>
  <p>TypeError: Object # has no method 'openFile'</p>
  </blockquote>
  <p>What do I need to do to fix this error and get the applet working?</p>