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

M

mcdeveloper

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.
 
M

mcdeveloper

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

MC
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top