Results 1 to 2 of 2

Thread: Javascript-applet communication

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

    Question Javascript-applet communication

    Hi,
    i've written an applet which reads text from text file stored on my desktop was_status.txt

    A.java

    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.awt.event.*;
    public class A extends Applet
    {
    private TextArea textArea = new TextArea(100, 800);
    String line="";

    public void init( )
    {
    String strPath ="C:/Documents and Settings/rajyalakshmi/Desktop/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;
    }


    }

    }

    o/p is : ON as the text file contains text: ON

    Javascript file has to read the ON value from applet
    The code test.htm

    <HEAD>
    <TITLE> New Document </TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    function sampleTest()
    {

    var s=document.TestApplet.returnFileValue().value ;
    alert(s);
    }
    </SCRIPT>

    </HEAD>

    <BODY onLoad="sampleTest()">
    <APPLET CODE="A.class" NAME="TestApplet" WIDTH = "200" HEIGHT = "200">
    </APPLET >
    </BODY>
    </HTML>

    when i execute this in browser it displays blank page instead of display "ON"

    Kindly ,can anyone suggest me on this

    Thanks & Regards,
    Lakshmi

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    var s=document.TestApplet.returnFileValue().value ;
    alert(s);
    Try:
    Code:
    window.alert(document.getElementsByName("TestApplet")[0].returnFileValue());
    Your markup needs some work, though. Run it through a validator.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •