Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

using JSObject, outside of main applet class

Thread view: 
alex_the_hart@yahoo.com - 28 Oct 2005 21:00 GMT
I want to use JSObject to trigger some javascript events, but I have a
fairly complicated piece of code, with many classes, and I want to call
JSObject from outside the main applet class.

The problem is this: The method that calls JSObject cannot be static,
because it needs to access the applet. So I need to call the method
with an object, but the only object I can use is the top level applet,
which isn't instantiated in my code, but by the browser.

This is some test code, to give an idea of what the problem is:

public class testJs extends JApplet implements Runnable
{
// this is the main applet

public void runJs(String str) // this function cannot be static,
                             //because it contains "this"
    {
        JSObject win = (JSObject) JSObject.getWindow(this);
        win.eval("alert(1);");
    }

}

public class callJs
{
// this class is where the js needs to be called.
   testJs.runJs(); // this doesn't work because it needs an object
                   // to run it with, but the only object I can use
                   // is the top level applet. But how can I reference
                   // the top level object?
}

Does anyone have a suggestion as to how this can be accomplished?

Many thanks for you help.

- Alex
Andrew Thompson - 31 Oct 2005 12:21 GMT
> public class callJs

// please use the common naming conventions for
// classes and methods.  Classes are
// EachWordUpperCase

> {

  private testJs applet;

   public CallJS(testJs theApplet) {
     applet = theApplet;
   }

   public void someMethod() {
> // this class is where the js needs to be called.
>     testJs.runJs(); // this doesn't work because it needs an object

       applet.runJs();

>                     // to run it with, but the only object I can use
>                     // is the top level applet. But how can I reference
[quoted text clipped - 4 lines]
>
> Many thanks for you help.

Please consider asking such questions in groups better
suited to beginners.
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.