A
alex_the_hart
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
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