Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > using JSObject, outside of main applet class

Reply
Thread Tools

using JSObject, outside of main applet class

 
 
alex_the_hart@yahoo.com
Guest
Posts: n/a
 
      10-28-2005
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

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      10-31-2005
wrote:

> 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
> // the top level object?
> }
>
> Does anyone have a suggestion as to how this can be accomplished?
>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
Decralation of class inside other class and definition outside this class =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki C++ 2 07-12-2007 11:52 PM
How to trap Mouse Move Event OutSide Main Application using VC++ jignesh2680@gmail.com Java 0 06-10-2005 10:11 AM
instanciate a class in a jar file with class.forname, while my main class is in another jar cyril Java 2 08-25-2004 06:55 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57