I have an JApplet which during "init" starts JFrame. There are some operations in that JFrame and user closes the JFrame finally.
Now I'd like to notify the browser via javascript that something is to be done.
How to accomplish that? If it was the applet alone, the simple function below would be good enough
public void notifyBrowser() {
JSObject browserWindow = JSObject.getWindow(this);
browserWindow.eval("try{RefreshFilesInLongue();}catch(e){alert('error');}");
}
but "this" in the code is referring to the applet object, and I don't know how to reach that object while I am in the JFrame.
JFrame is called like below in order to receive focus:
public void init() {
paramPostUrl = this.getParameter("postUrl");
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
ScanFrame scanFrame = new ScanFrame();
scanFrame.setPostUrl(paramPostUrl);
scanFrame.setVisible(true);
try {
Thread.sleep(300L);
scanFrame.toFront();
} catch (InterruptedException ex) {
Logger.getLogger(Applet.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
So my questions are:
1. how can I call notifyBrowser(), while being in scanFrame object
2. or how to detect that scanFrame was closed and being in applet object successfully call notifyBrowser?
Thanks for your help.
So modified code is like that:
public class Applet extends javax.swing.JApplet {
...
public void init() {
paramPostUrl = this.getParameter("postUrl");
myApplet = this;
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
initComponents();
ScanFrame scanFrame = new ScanFrame(myApplet);
...
and ScanFrame
public class ScanFrame extends javax.swing.JFrame implements ScannerListener {
...
private JApplet appletObj;
public ScanFrame(JApplet myApplet) {
appletObj = myApplet;
....
private void sendScannedDocumentToCallingApp() {
....
JSObject browserWindow;
browserWindow = JSObject.getWindow((JApplet)appletObj);
browserWindow.eval("try{RefreshFilesInLongue();}catch(e){alert('error');}");
}
and the error I get:
Exception in thread "AWT-EventQueue-2" java.util.NoSuchElementException
at java.util.LinkedList.getFirst(Unknown Source)
at java.awt.SequencedEvent.getFirst(Unknown Source)
at java.awt.SequencedEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)