accessing java methods in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • makthar
    New Member
    • Aug 2007
    • 13

    accessing java methods in javascript

    hi
    i have the following java applet progam and the javascript
    the problem is that when the javascript tries to access the applet method it gives me an error as follows
    document.form1. myApplet is null or not an object. plz provide me a soln for this. the code is as
    html file
    [code=html]<HTML>
    <HEAD>
    <SCRIPT type="text/javascript">
    function getScreenDim() {
    alert(document. form1.hello.val ue);
    str = document.form1. myApplet.getScr een();
    alert(str);
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM name="form1">
    <INPUT type="button" name="hello" value="call JAVA" onClick="getScr eenDim()">
    <applet code="javascrip tTest\InJava2" name="myApplet" width="20" height="20">
    </applet>


    </FORM>
    </BODY>
    </HTML>[/code]


    java file
    [code=java]
    package javascriptTest;


    import java.applet.App let;
    import java.awt.Toolki t;
    //(IE and Netscape ok)
    public class InJava2 extends Applet {
    public String getScreenWidth( ) {
    return String.valueOf( Toolkit.getDefa ultToolkit().ge tScreenSize().w idth);
    }
    public int getScreenHeight () {
    return Toolkit.getDefa ultToolkit().ge tScreenSize().h eight;
    }
    public static int getScreen() {
    return 25;
    }
    }[/code]

    thanks
    mansoor
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, mansoor. Welcome to TSDN!

    I award 8 points for creative use of [B] tags, but I have to deduct 8 points for not using [CODE] tags. Better luck next time.

    Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      See this link.

      Move the applet out of the form.

      Comment

      Working...