Tuesday, February 9, 2010

Passing A Frame From Javascript to Applet

Passing A Frame From Javascript to Applet

I mentioned a few weeks back the frustration of trying to find a way to replace the Javascript confirm function with something a little less constricting. I have found the solution: it is possible to call an applet's public method from Javascript, and get a value back. The Javascript function is:

function window.confirmDialogYN(parent, prompt, title)
{
var reply = document.myApplet.confirmYN(prompt, title);
return(reply);
}
The applet requires a public method that calls JOptionPane.showConfirmDialog--and with a little effort, you can produce a variety of methods in that applet to provide a wide range of modal dialog boxes. The reason is that there are hundreds of calls to Javascript confirm, many of which require some rather convoluted prompts to make sure the user clicks the correct button!

My remaining problem is that JOptionPane.showConfirmDialog pops up the modal dialog box in the middle of the screen--not necessarily the middle of the browser that invokes it. The reason is that I'm specifying null for the first parameter, the Component that is the parent. The reason is that I can't quite figure out what the correct way in Javascript to get the Frame that is the parent of the applet. I've tried Javascript's document, document.applet, window, document.window--without luck.

UPDATE: Of course, since there is no type checking in Javascript, there's nothing to tell you that the types don't match!

UPDATE 2: Stupid, stupid, stupid! All I needed was to pass this as the first parameter.

No comments:

Post a Comment