当Applet.stop()叫什么名字? [英] When is Applet.stop() called?
问题描述
我实验使用Eclipse及其Applet查看我的小程序。 Applet查看器出现在Eclipse中的顶部和小程序执行过程中我点击Eclipse的图标,将其从任务栏中最大化。然后Applet查看器失去焦点和 Applet.stop()
被调用。
当我尽量减少了Eclipse,Applet查看进入前再次获得焦点和 Applet.start()
被调用。这得一塌糊涂结束。
这是正常行为,对浏览器调用 Applet.stop
一旦用户切换到另一个选项卡或最小化浏览器我可以禁用,我想停止
从来没有被调用。
也许我缺少的东西线程
我的code是这样的:
公共类AppletApp扩展JApplet的{ 公共无效的init(){
super.init();
的System.out.println(AppletApp.init());
} 公共无效的start(){
的System.out.println(AppletApp.start()); 尝试{
SwingUtilities.invokeAndWait(新的Runnable(){
@覆盖
公共无效的run(){
。的getContentPane()加(新的JLabel(测试标签));
}
});
}赶上(InterruptedException的E){
}赶上(的InvocationTargetException E){} 可运行可运行=新的Runnable(){
@覆盖
公共无效的run(){
//为DJ浏览器组件
NativeSwing.initialize();
NativeInterface.open(); //连接到服务器并启动消息交换
Client.init(用户界面中);
userInterface.authenticate(); NativeInterface.runEventPump();
}
};
线程t =新主题(可运行);
t.start();
} 公共无效停止(){
的System.out.println(AppletApp.stop());
} 公共无效的destroy(){
的System.out.println(AppletApp.destroy());
}
}
它是一个浏览器调用Applet.stop一旦用户正常行为
切换到另一个选项卡或浏览器最小化?
块引用>是的,这是正常的。从javadoc的:
由浏览器或applet viewer调用,通知此applet它
应该终止执行。这就是所谓的在Web页面
包含该applet已取代另一个页面,也只是
之前小程序予以销毁。
块引用>当您切换选项卡上,我认为包含它的网页已经被替换,因此它是合乎逻辑的
停止()
被调用。
我可以禁用,我想从来没有停止被调用。
块引用>没有你不行,你就没有这方面的控制。但是,你可以依靠
的init()
和的destroy()
方法,而不是启动()
和停止()
。开始()
和停止()
都是为了恢复/暂停任何消耗这是没有必要的,如果不可见的资源(例如动画是没有意义的,如果不可见)。I experiment with my applet using Eclipse and its Applet Viewer. The Applet Viewer appears on the top of Eclipse and during Applet execution I click on Eclipse icon to maximize it from task bar. Then Applet Viewer loses the focus and
Applet.stop()
gets called.When I minimize Eclipse, Applet Viewer goes to front again, gains focus and
Applet.start()
gets called. This ends up in a complete mess.Is it normal behavior for a browser to call
Applet.stop
once user changes to another Tab or minimizes the browser Can I disable that, I wantstop
never been called.Maybe I am missing something in threads.
My code is something like this:
public class AppletApp extends JApplet { public void init() { super.init(); System.out.println("AppletApp.init()"); } public void start() { System.out.println("AppletApp.start()"); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { getContentPane().add(new JLabel("Test Label")); } }); } catch (InterruptedException e) { } catch (InvocationTargetException e) {} Runnable runnable = new Runnable() { @Override public void run() { //For DJ Browser Component NativeSwing.initialize(); NativeInterface.open(); //connect to server and start message exchange Client.init(userInterface); userInterface.authenticate(); NativeInterface.runEventPump(); } }; Thread t = new Thread(runnable); t.start(); } public void stop() { System.out.println("AppletApp.stop()"); } public void destroy() { System.out.println("AppletApp.destroy()"); } }
解决方案Is it normal behavior for a browser to call Applet.stop once user changes to another Tab or minimizes the browser?
Yes it is normal. From the javadoc:
Called by the browser or applet viewer to inform this applet that it should stop its execution. It is called when the Web page that contains this applet has been replaced by another page, and also just before the applet is to be destroyed.
When you switch tab, I consider that the containing web page has been replaced hence it is logical that
stop()
is invoked.Can I disable that, I want stop never been called.
No you can't, you don't have control on that. However, you could rely on the
init()
and thedestroy()
methods instead ofstart()
andstop()
.start()
andstop()
are meant for resuming/pausing anything that consumes resources which are not necessary if not visible (for example an animation is pointless if not visible).这篇关于当Applet.stop()叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!