Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling own Java code from Javascript.

    Hello, I'm making a Javascript implementation for my Java program. But I'm having a proplem. I want to call my own Java code from the Javascript script.
    Is that possible?

    Thanks,
    enderp

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by enderp View Post
    Hello, I'm making a Javascript implementation for my Java program. But I'm having a proplem. I want to call my own Java code from the Javascript script.
    Is that possible?

    Thanks,
    enderp
    Google is your friend!

    http://www.rgagnon.com/javadetails/java-0170.html
    http://www.woodger.ca/js_jvint.htm

    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 03-18-2012 at 05:40 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Google is your friend!

    http://www.rgagnon.com/javadetails/java-0170.html

    It is your responsibility to die() if necessary….. - PHP Manual
    I've seen that one, but it doesn't show how to call your own packaged Java code.
    I have the js files in the script directory, and the java classes in the bin directory.


    Look, it's not for web development, but scripting for a game.
    Last edited by enderp; 03-18-2012 at 05:49 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    The JavaScript code doesn't really care where the Java comes from. The Java *must* already be present on the page for JavaScript to call it.

    The <applet> tag allows you to specify the path to your JS class and, at the same time, give the applet a name= that can be seen by JavaScript. JavaScript refers to the applet by the name= value and is unaware of the actual .class file being used.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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