如何模拟一个模式对话框从applet中? [英] How do I simulate a modal dialog from within an Applet?
问题描述
在调用setVisible(真),我请拨打以下code以启动一个模态对话框:
On setVisible(true), I call the following code to start a modal dialog:
private synchronized void startModal () {
try {
if (SwingUtilities.isEventDispatchThread()) {
EventQueue theQueue = getToolkit().getSystemEventQueue();
while (isVisible()) {
AWTEvent event = theQueue.getNextEvent();
Object source = event.getSource();
if (event instanceof ActiveEvent) {
((ActiveEvent) event).dispatch();
} else if (source instanceof Component) {
((Component) source).dispatchEvent(event);
} else if (source instanceof MenuComponent) {
((MenuComponent) source).dispatchEvent(event);
} else {
System.err.println("Unable to dispatch: " + event);
}
}
} else {
while (isVisible()) {
wait();
}
}
} catch (InterruptedException ignored) { }
}
这在大多数的浏览器好了。但是,Opera和Safari for Windows中,我面临着以下大讨厌的异常:
This works just great in most browsers. However, in Opera and Safari for Windows, I am confronted with the following big-nasty-exception:
java.security.AccessControlException: access denied (java.awt.AWTPermission accessEventQueue)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkAwtEventQueueAccess(Unknown Source)
at java.awt.Toolkit.getSystemEventQueue(Unknown Source)
有没有在这些浏览器生成假模态对话框的变通方法?
Is there a workaround for generating fake-modal dialogs in these browsers?
推荐答案
具有歌剧院有问题可能是歌剧有命名为opera.policy自己的java.policy文件(下Opera_installation_directory \\ classes文件夹)的原因。虽然,在我的Opera安装,我看不出是不是在Opera批准,但批准在默认的java.policy文件许可。
The reason of having a problem with Opera might be that Opera has its own java.policy file named as opera.policy (under Opera_installation_directory\classes folder). Though, in my Opera installation, I couldn't see any permission that is not granted in Opera but granted in the default java.policy file.
这篇关于如何模拟一个模式对话框从applet中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!