0

我有一个包含多个小程序的页面(是的,它很旧)。这些小程序之一覆盖了 stop 方法,如下所示:

@Override public void stop() {

 System.out.println("Stop called!");

}

但是,当我这样做时,当我切换选项卡或执行任何其他应该调用stop(). 覆盖也发生了同样的问题destroy()。但是,start()andinit()函数按预期工作。

我的小程序正在扩展另一个类,而后者又扩展了 JApplet。我这样做是为了让我的所有小程序都可以访问特定的函数(在这个中间类中定义)。这些小程序还为重复性任务创建其他线程,但我认为这不会影响生命周期方法。我不确定在哪里看这一点,焦点功能或其他类似的东西是否可能阻止生命周期方法执行,或者一页上有多个小程序会导致这些方法出现问题?预先感谢。

编辑:我已经在我的服务器上发布了一个 SSCCE 以显示此行为单击此处运行此处下载源,这是一个启动线程的简单小程序,它调用父小程序中打开 JDialog 的方法。您会注意到,您可以在对话框打开时关闭浏览器选项卡(只要还有其他选项卡打开),并且在 IE10 中不会出现停止或销毁打印语句。最重要的是,JVM 继续运行,Java 控制台没有关闭。但是,如果您在关闭浏览器窗口之前确认弹出窗口,则一切正常。

那么,接下来的问题是,如果有人在弹出窗口打开时关闭浏览器窗口,我如何杀死额外的线程和弹出窗口本身?

4

3 回答 3

1

JDialog提到的是使用创建的JOptionPane。引用javadoc

所有对话框都是模态的

模态对话框有效地阻止小程序阻止小程序中的stopdestroy方法被调用。您可以简单地使对话框非模态

popup.setModal(false);
于 2013-09-29T14:06:57.543 回答
1

下载并展开 Zip 并将 2 个源文件转换为 SSCCE(根据定义,SSCCE 是一个源文件)后,我注意到 IE9 中的行为相同。

在我看来,这是浏览器/JVM 交互错误的又一个例子。在 FF 中,当对话框打开时,用户无法关闭页面或更改选项卡。这导致了我们所期望的行为,因为对话框必须在小程序选项卡关闭(或选项卡更改或浏览器关闭)之前关闭。

在 IE9(和 10,根据您的报告)中,尽管对话框可见,但仍可以访问该页面,从而导致所有问题。

不幸的是,我能想到的唯一解决方法没有(工作)。有时可以通过 a 检测到必要的事件ComponentListener,但在这种情况下,它不会在关闭选项卡或更改选项卡时触发。

所以,我建议你在bug 数据库中搜索类似的东西。如果您一无所获,请提交一份新报告,看看甲骨文对此事有什么看法。如果这是一个错误,他们认为是 IE 的错,他们可以用 MS 解决。

于 2013-10-02T11:00:04.017 回答
0

I switch tabs, or do anything else that should call stop(). The same problem is happening with overriding destroy(). However, the start() and init() functions work as expected.

Life Cycle of an Applet Doc page says:

When the user leaves the page, for example, to go to another page, the browser stops and destroys the applet. The state of the applet is not preserved. When the user returns to the page, the browser intializes and starts a new instance of the applet.

So yes I am having the correct result when i try to change the page on which applet is running, the stop() and destroy() method gets called and stopping and destroying gets printed. If by switching the tab you are meaning selecting one tab among the opened tabs, this is not to cause stop() and destroy() get called. However if you run JApplet directly from an applet viewer using Netbeans/Eclipes you will see that window state change(e.g., iconified, normalized) will cause stop() get called. destroy() will be called if you close the JApplet viewer.

You'll notice that you can close the browser tab while the dialog is open (as long as there are other tabs open) and neither the stop or destroy print statements will occur in IE10.

well i have tested with IE9 as i don't have IE10 now, i noticed in IE9 unlike in Firefox that the JDialouge lets switching tab among the opened tabs but it let neither the browser nor the page containing the applet get closed until acknowledging it. So it has something to do with IE10. you can try to use javascript to call an applet function to force it to be exited on window close event. I am not sure about this though as i mentioned, i don't have IE10.

On top of that, the JVM keeps running, and the Java console does not close. However, if you acknowledge the pop-up before closing the browser window, everything functions as expected.

I am a little bit confused here. Actually both Firefox and in IE9, i have experienced that after closing the page containing JApplet, jp2launcher.exe takes at most 2 mins time to exit itself and java.exe. In the mean time if you reopen the page containing the applet, it will start instantly without asking for any permission as it would ask first time when it got loaded.

于 2013-10-03T17:49:48.897 回答