PDA

View Full Version : getting java applet method value in javascript variable



r_v_vinayak
11-17-2006, 07:55 AM
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?

codeexploiter
11-17-2006, 08:42 AM
I think you can read that describes Java to JavaScript communication at Sun's Java Documentation (http://java.sun.com/products/plugin/1.3/docs/jsobject.html)