Can a Java Applet minimize its browser window?

核能气质少年 提交于 2019-12-24 10:55:32

问题


My applet pops up in a browser window and then creates a separate JFrame. I'd like to minimize the original hosting browser window. Can I do it from the applet?


回答1:


You can't minimize a browser window from the Applet or with Javascript. You can try playing around with the Javascript window blur and focus to see if you can make them work for you. Communicating with JS should be possible as follows

import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
class MyApplet extends Applet {
  public void init() {
    JSObject win = JSObject.getWindow(this);
    JSObject doc = (JSObject) win.getMember("document");
    JSObject loc = (JSObject) doc.getMember("location");

    String s = (String) loc.getMember("href");  // document.location.href
    win.call("f", null);                 // Call f() in HTML page
  }
}

Code untested and taken from Oracle docs




回答2:


No, you can't do it. Your applet does not gain control over the calling window and therefore can't minimize (or otherwise manipulate) that window.



来源:https://stackoverflow.com/questions/11510661/can-a-java-applet-minimize-its-browser-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!