Javascript to Java Applet communication

后端 未结 4 1031
余生分开走
余生分开走 2020-12-06 03:19

I am trying to pass a selected value from HTML drop-down to an Applet method, using setter method in the Applet. But every time the Javascript is invoked it shows \"object d

相关标签:
4条回答
  • 2020-12-06 03:55

    Try changing the id parameter in your applet tag to name instead.

    <applet name="decisiontreeapplet" ...>
    </applet>
    
    0 讨论(0)
  • 2020-12-06 03:56

    Try passing parameters using the param tag:

    http://download.oracle.com/javase/tutorial/deployment/applet/param.html

    0 讨论(0)
  • 2020-12-06 04:03

    Change..

    document.decisiontreeapplet
    

    ..to..

    document.getElementById('decisiontreeapplet')
    

    ..and it will most likely work.

    E.G.

    HTML

    <html>
    <body>
    <script type='text/javascript'>
    function callApplet() {
        msg = document.getElementById('input').value;
        applet = document.getElementById('output');
        applet.setMessage(msg);
    }
    </script>
    <input id='input' type='text' size=20 onchange='callApplet()'>
    <br>
    <applet
        id='output'
        code='CallApplet'
        width=120
        height=20>
    </applet>
    </body>
    </html>
    

    Java

    import javax.swing.*;
    
    public class CallApplet extends JApplet {
    
        JTextField output;
    
        public void init() {
            output = new JTextField(20);
            add(output);
            validate();
        }
    
        public void setMessage(String message) {
            output.setText(message);
        }
    }
    

    Please also consider posting a short complete example next time. Note that the number of lines in the two sources shown above, is shorter that your e.g. applet, and it took me longer to prepare the source so I could check my answer.

    0 讨论(0)
  • 2020-12-06 04:12

    I think the <applet> tag is obsolete and <object> tag shoudl be used instead. I recall there was some boolean param named scriptable in the object tag.

    Why you do not use deployment toolkit ? It would save you a lot of trying - see http://rostislav-matl.blogspot.com/2011/10/java-applets-building-with-maven.html for more info.

    0 讨论(0)
提交回复
热议问题