2
import java.awt.*;
import java.applet.*;

public class MyApplet extends Applet{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    String dString = "Value is null";
    String gPath="";

    public void get_path(){
        gPath = this.getParameter("path");
        if(gPath == null)
            gPath = dString;
        //setBackground(Color.cyan);
    }

    public void paint(Graphics g){

        g.drawString(gPath, 20, 30);
    }
}

HTML code:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8"/>
        <title> Upload File </title>
        <script type="text/javascript">
            var sys_path;

            function print_path(){
            sys_path = document.getElementById('name').value;
            document.app.get_path();
            document.write(sys_path);
            }

        </script>
        <applet code="MyApplet.class" name="app" width="300" height="200">
            <param name="path" value="&{sys_path};">    
        </applet>

    </head>

    <body>
        <form>

            Path:<input type="text" id="name" \>
            <input type="button" value="click" onClick="print_path();" />       

        </form>
    </body>
</html>

Explanation:

In these code I'm trying to take input from text box and display in the applet. I'm trying this couple of days and unable to find a way. Please help me regarding this. Thanks in advance!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Isan Sahoo
  • 384
  • 2
  • 10
  • You can take a look at [this](http://dillonbuchanan.com/programming/communicating-between-java-applets-and-javascript/) post or this [SO](http://stackoverflow.com/questions/12585022/how-to-pass-values-from-html-page-to-java-applet) posting. – Phoenix Apr 23 '15 at 05:07
  • *"In these code I'm trying to take input from text box and display in the applet."* So why is the JS taking the input value to from the text box and (trying to) write it to the **HTML?** – Andrew Thompson Apr 24 '15 at 03:23

0 Answers0