Applet.stop() 什么时候被调用? [英] When is Applet.stop() called?

查看:26
本文介绍了Applet.stop() 什么时候被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Eclipse 及其 Applet Viewer 来试验我的小程序.Applet 查看器出现在 Eclipse 的顶部,在 Applet 执行期间,我单击 Eclipse 图标以从任务栏中将其最大化.然后 Applet Viewer 失去焦点并且 Applet.stop() 被调用.

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.

当我最小化 Eclipse 时,Applet Viewer 再次回到前面,获得焦点并且 Applet.start() 被调用.结果一团糟.

When I minimize Eclipse, Applet Viewer goes to front again, gains focus and Applet.start() gets called. This ends up in a complete mess.

一旦用户切换到另一个选项卡或最小化浏览器,浏览器就会调用 Applet.stop 是否正常?我可以禁用它吗,我想要 stop从未被调用过.

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 want stop never been called.

也许我在线程中遗漏了一些东西.

Maybe I am missing something in threads.

我的代码是这样的:

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()");
    }
}

推荐答案

浏览器调用 Applet.stop 一次用户是正常行为吗更改到另一个选项卡或最小化浏览器?

Is it normal behavior for a browser to call Applet.stop once user changes to another Tab or minimizes the browser?

是的,这是正常的.来自 javadoc:

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.

当您切换选项卡时,我认为包含的网页已被替换,因此调用 stop() 是合乎逻辑的.

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.

不,你不能,你无法控制.但是,您可以依赖 init()destroy() 方法而不是 start()stop().start()stop() 用于恢复/暂停消耗资源的任何内容,如果不可见则不需要(例如,动画如果不可见则毫无意义).

No you can't, you don't have control on that. However, you could rely on the init() and the destroy() methods instead of start() and stop(). start() and stop() 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆