Hi all,
I'm trying to call an applet method from Javascript, the call works OK,
but the method is returning a value before the main section of the
applet code has executed, causing the wrong value to be returned. I
would appreciate any guidance:
Applet code (relevent sections only):)
public class BandwidthTestApplet extends Applet {
...
public static boolean usrHighBand = false; //this is problem variable
...
public void start(){
...some calculations and stuff
these ulimately change the usrHighBand varaible
}
public boolean getClientBandwidth(){ //method called by javascript
return usrHighBand;
}
}
What seems to be happening is that the javascript is calling the method
before the applet has done anything, so returns false. If the page is
refreshed the value returned is the one that should have been returned
the first time round. Am i being stupid here and missing something
obvious, or is there a way to force my script to execute after the
applet has finished?
Cheers for any help.
Jim
David Lesaffre - 07 May 2004 08:21 GMT
> Hi all,
> I'm trying to call an applet method from Javascript, the call works OK,
[quoted text clipped - 27 lines]
> Cheers for any help.
> Jim
public class BandWidthTestApplet extends Applet {
private boolean initialized = false;
public void start() {
...
initialized = true;
}
..
}
Now you can provide a getter isInitialized() in your applet for your
javascript to test for; or you can wait for the initialized variable to be
true in the getClientBandwidth() method.
Fahd Shariff - 07 May 2004 11:22 GMT
Im not sure what the problem is but you could try if any of the
following solve the problem:
- using an init() method instead of the start method.
- calling the start method of the applet explicitly from within your
javascript code before getClientBandwidth().
- sleeping for a while before calling the getClientBandwidth in
javascript.
Fahd
http://www.fahdshariff.cjb.net
khtulhu Dragon - 07 May 2004 14:44 GMT
> Im not sure what the problem is but you could try if any of the
> following solve the problem:
[quoted text clipped - 7 lines]
> Fahd
> http://www.fahdshariff.cjb.net
Sticking the conents of my start method into init() did indeed solve the
problem, it runs a little more slowly now but at least it works!
Thanks.
Roedy Green - 07 May 2004 19:11 GMT
>What seems to be happening is that the javascript is calling the method
>before the applet has done anything,
That code is just to generate the tags to start the applet. You need
something quite different to get the Applet to talk back. The Applet
has to co-operate. Applets don't naturally return a result.
Basically I think the Applet has to invoke a Javascript function
passing it a parameter.
I have never done this.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.