BuddhiBase

my thoughts .....!

Java Script - Java Applet Communication - Live Connect

One comment

Here is an example of how to communicate with Java Applet using Java Script (vice-versa)

//--------------------------------TestApplet.java------------------------------------------------

import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;

public class TestApplet extends JApplet implements ActionListener
{
    public String displayString = "India";

    public TestApplet() throws HeadlessException
    {
        super();
    }

    public void init()
    {
      
    }

    public void paint(Graphics g)
    {
        g.drawString("Hello world! " + displayString, 50, 25);
    }

    public void actionPerformed(ActionEvent arg0)
    {

    }

    public void ChangeText(String input)
    {
        try
        {
            displayString = input;
            repaint();
            System.out.println("screen refresh done");

            //call the java script function with the parameter list...
            JSObject win = JSObject.getWindow(this);
            //Parameter List...
            String args2[] = { "" };
            //Function Call
            win.call("testForm", args2);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

}

//--------------------------------Test.html------------------------------------------------

<html>
 <head>
  <title>HTML Page</title>
  <SCRIPT>
  function testForm()
  {  
  alert("Call from Java Applet - Now the form is being submited");  
  document.forms[0].submit();
  }
  </SCRIPT>
 </head>
 <body bgcolor="#FFFFFF">
 <form method=post action=go.asp>
 <APPLET CODE="TestApplet.class" NAME="muthuapplet" WIDTH=150 HEIGHT=175></APPLET> 
    <hr>
    <A HREF="#" onClick="javascript:document.applets.muthuapplet.ChangeText('Europe');">Change</A><BR>
 </form>
 </body>
</html>

Share Facebook Profile

Written by muthuveerappan

Monday 16 May 2005 at 04:46 am

Posted in Technology

One comment

  1. I will continue to visit enjoyed the reading thanks

    Alena

    Alena

    (URL)

    07-10-’06 14:50

Leave a Reply

(optional field)
(optional field)
To prevent automated commentspam we require you to answer this silly question

Comment moderation is enabled on this site. This means that your comment will not be visible until it has been approved by an editor.

Remember personal info?
Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.