Results 1 to 2 of 2

Thread: getting java applet method value in javascript variable

  1. #1
    Join Date
    Nov 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default getting java applet method value in javascript variable

    Hi, I have an applet by name TestApp,

    import java.applet.*;
    import java.io.*;
    public class A extends Applet
    {

    public String line="";

    public void init( )
    {
    String strPath ="D:/WAS_Status.txt";
    try
    {
    BufferedReader objReader = new BufferedReader(new FileReader(strPath));
    line = objReader.readLine();

    }catch( IOException e)
    {
    e.printStackTrace();
    }
    System.out.println("val :"+line);
    }

    public boolean returnFileValue()
    {
    if("ON".equals(line))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    }

    In an html :
    <HTML>
    <HEAD>
    <SCRIPT language="JavaScript">
    var line='';
    function loadAppContent()
    {
    line=document.TestApplet.returnFileValue();
    alert("val : "+line);

    }
    </SCRIPT>
    </HEAD>
    <BODY onload="loadAppContent()">
    <APPLET CODE="A.class" NAME="TestApplet" >
    </APPLET >
    </BODY>
    </HTML>

    But I am not able to get value either as true or false.
    line=document.TestApplet.returnFileValue(); Its says object doesnt support this property.
    I tried line=document.TestApplet.line; Gets val as undefined.
    The line variable of Applet will return either ON or OFF value.
    Pls suggest where it has gone wrong?

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I think you can read that describes Java to JavaScript communication at Sun's Java Documentation

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •