javascript call from instantiated class which extends JApplet
Robert Kennedy
Ranch Hand
Joined: Jun 27, 2008
Posts: 63
posted
0
Hello,
In my applet the class which get initialized extends JApplet. public class HomeApplet extends JApplet
The HomeApplet class instantiates another class: Route route = new Route();
public class Route extends JApplet impelments Runnable - here I have extended JApplet because I wish to make calls from this class to Javascript methods in the web page
This call fails with the following exception Exception in thread "Thread-27" netscape.javascript.JSException at netscape.javascript.JSObject.getWindow(Unknown Source) at App.FileUploader.Route.launchRouteManager(Route.java:117)
Must I HomeApplet or can I make the calls from my Route class (which extends JApplet)
Thanks!
Norm Radder
Ranch Hand
Joined: Aug 10, 2005
Posts: 681
posted
0
Not sure why its happening. The applet that is loaded by the browser has connections to the browser via the AppletContext and AppletStub interfaces. The applet you've created would NOT have these connections.
Robert Kennedy
Ranch Hand
Joined: Jun 27, 2008
Posts: 63
posted
0
Hello,
Thank yo for your response. Yes this makes sense. Obviously the applet passed in as a parameter for JSObject must be the applet on the page.
If I create a pointer to the object returned by JSObject can I keep it alive for the life of the applet and pass it to the classes which must make calls to the Javascript methods or should I get a new pointer each time via the originating Applet class
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
You should be able to keep a reference to the object around.
Just to expand on what Norm said: you should only have a single class extending Applet (or JApplet) in your code base, and your code should not call its constructor - the browser does that automatically.