File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes javascript call from instantiated class which extends JApplet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "javascript call from instantiated class which extends JApplet" Watch "javascript call from instantiated class which extends JApplet" New topic
Author

javascript call from instantiated class which extends JApplet

Robert Kennedy
Ranch Hand

Joined: Jun 27, 2008
Posts: 63
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

private void launchRouteManager(){
...
JSObject window = JSObject.getWindow (this);
...
}

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: 690
    
    1
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
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: 42594
    
  65
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript call from instantiated class which extends JApplet