Javascript -> Applet: variable reset after method call from javascript?!

Discussion in 'Java' started by mcdeveloper, Jun 12, 2006.

  1. mcdeveloper

    mcdeveloper Guest

    Hi all,

    I 've got this strange (?) problem. I call a method from javascript, setting a private member variable USERENTERED. Within the method, everything goes fine, if I print the variable it has changed. However, as soon as I use the variable in another method, it has changed back to its initial value (which is -1 in my case).

    I don't see what I'm doing wrong, the variable is not local but a member variable. This is the method being called:


    public void setUserEnteredValue(String x)
    {
    try
    {
    double d = Double.parseDouble(x);
    int xPos = (int)((d * FACTOR) + MARGINLEFT - (SCALEMIN * FACTOR));

    this.USERENTERED = xPos;
    System.out.println("User entered" + USERENTERED);

    }
    catch (NumberFormatException nfe) { System.out.println("failed to set user input, input is " + x ); }
    }


    If the variable is made static, it DOES change, but this is undesired because (of course) all other instances of the applet will have a changed variable. I'm not setting the variable elsewere. Morveover, I'm using this technique for other variables as well and I've got the same problem with those.

    Any ideas?

    MC.
     
    mcdeveloper, Jun 12, 2006
    #1
    1. Advertising

  2. mcdeveloper

    mcdeveloper Guest

    Solved. Didn't have to do anything with Java, had to do with being stupid (calling wrong control, d'oh!)

    MC
    "mcdeveloper" <> wrote in message news:6ceff$448d5609$3e3a29f2$...
    Hi all,

    I 've got this strange (?) problem. I call a method from javascript, setting a private member variable USERENTERED. Within the method, everything goes fine, if I print the variable it has changed. However, as soon as I use the variable in another method, it has changed back to its initial value (which is -1 in my case).

    I don't see what I'm doing wrong, the variable is not local but a member variable. This is the method being called:


    public void setUserEnteredValue(String x)
    {
    try
    {
    double d = Double.parseDouble(x);
    int xPos = (int)((d * FACTOR) + MARGINLEFT - (SCALEMIN * FACTOR));

    this.USERENTERED = xPos;
    System.out.println("User entered" + USERENTERED);

    }
    catch (NumberFormatException nfe) { System.out.println("failed to set user input, input is " + x ); }
    }


    If the variable is made static, it DOES change, but this is undesired because (of course) all other instances of the applet will have a changed variable. I'm not setting the variable elsewere. Morveover, I'm using this technique for other variables as well and I've got the same problem with those.

    Any ideas?

    MC.
     
    mcdeveloper, Jun 13, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. troy makaro
    Replies:
    8
    Views:
    764
    Andrew Thompson
    Oct 8, 2005
  2. Dag Sunde
    Replies:
    8
    Views:
    3,092
    Andrew T.
    May 10, 2006
  3. CADD
    Replies:
    22
    Views:
    10,030
    Nikita the Spider
    Sep 3, 2006
  4. sck10
    Replies:
    2
    Views:
    421
    sck10
    Sep 4, 2006
  5. crazytazo
    Replies:
    3
    Views:
    1,258
    Daniel Pitts
    Oct 7, 2008
Loading...

Share This Page