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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Help me plz, my mind is disintegrating!

    I'm currently just trying to get the js/applet connection to work. I am pretty green on programming but after I got one method to return a number from the applet to the js I thought it no big deal. The syntax didn't seem, and doesn't seem, difficult to me. However either there is a green little goblin in there somewhere or I've totally lost it.

    Basically I have this one method addToCount() that works, not perfectly, once it generated a strange exception, but 99% of the time if I call oApplet with addToCount(); I get a return value that is displayed properly in an alert message. Whatever other function I try however, even if I only replace that same call ie. oApplet.addToCount() for oApplet.addBah() does absolutely nothing. The button becomes completely silent.

    Hopefully someone can tell me how stupid I've been or I'm at the risk of pulling my hair out by the roots. It's just not enough code to be causing trouble, could there be something wrong with my machine?



    in the body------------------------------------------
    <object type="application/x-java-applet"
    code="Omg.class" id="ExampleApplet">
    </object>
    <input type="button" value="ok" onclick="sendAndRecieve()" />
    -----------------------------------------------------

    When I do this it doesn't work!
    The js file--------------------------------------------
    function sendAndRecieve(){
    var oApplet = document.getElementById("ExampleApplet");
    var iAppletReturnValue = oApplet.addBah();

    alert("the applet says: " + iAppletReturnValue);
    }
    -----------------------------------------------------

    Only this method works, and that is whatever I try to exchange it for...
    The js file--------------------------------------------
    function sendAndRecieve(){
    var oApplet = document.getElementById("ExampleApplet");
    var iAppletReturnValue = oApplet.addToCount();

    alert("the applet says: " + iAppletReturnValue);
    }
    -----------------------------------------------------

    The applet-------------------------------------------

    import javax.swing.JApplet;

    public class Omg extends JApplet {
    private int tickMe = 10;

    public void init(){}

    public int addBah(){
    int x = 1;
    return x;
    }

    public int addToCount(){
    tickMe++;
    return tickMe;
    }

    }
    -------------------------------------------------------

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I don't suppose you wrote the first method, tested it, then wrote the second and tried testing that?

    My guess: clear your .class file from the cache. It's using the old version from before you added the second method.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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