Call Javascript function with parameters from Java program
<p>I have Java Swing application. When user clicks on MenuItem I want to show graph on HTML page, using JavaScript.
Java code:</p>

<pre><code> if(e.getActionCommand().equals("show graph")){
        if(mainPopulation != null) {
            double[] myPoints = mainPopulation.getElements();
            Desktop d = Desktop.getDesktop();
            try {
                d.open(new File("D:/fp.html"));
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
</code></pre>

<p>JavaScript code:</p>

<pre><code>&lt;html&gt;
 &lt;head&gt;
  &lt;script type="application/x-javascript"&gt;
    function draw(params) {
      var canvas = document.getElementById("canvas");
      if (canvas.getContext) {
        var ctx = canvas.getContext("2d");
        ctx.font = '10pt Calibri';
        ctx.fillStyle = 'blue'; 
        for(i=0;i&lt;params.length;i++){
            ctx.beginPath();
            ctx.moveTo(params[i], params[i+1]);
            ctx.lineTo(params[i + 2], params[i + 3]);
            ctx.stroke();           
            ctx.fillText('(' + params[i].toString() + ';' + params[i +1].toString() + ')', params[i], params[i+1]);
            i += 1;
        }
      }
    }
  &lt;/script&gt;
 &lt;/head&gt;
 &lt;body onload="draw([10,10,20,20,30,30,40,40,40,100,50,90,70,90,60,50]);"&gt;
   &lt;canvas id="canvas" width="1000" height="1000"&gt;&lt;/canvas&gt;
 &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>How can I call function <strong>draw</strong>(on <strong>body onload</strong>) with parameter <strong>double[] myPoints</strong>, dynamically change HTML from Java program?</p>

<p>Thanks.</p>
