If I call the below line in body onload method applet is returning something. But I like to invoke the below line after the Applet process finished or at some applet event.
Then that method should return "null" -or some other special value- until its result is valid. You can use the JavaScript timeout functionality to keep calling the method; be sure to stop calling once the result is valid.