如何从 Applet 中模拟模态对话框? [英] How do I simulate a modal dialog from within an Applet?
问题描述
在 setVisible(true) 上,我调用以下代码来启动模态对话框:
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) { }
}
这在大多数浏览器中都很好用.但是,在 Windows 的 Opera 和 Safari 中,我遇到了以下令人讨厌的异常:
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 出现问题的原因可能是Opera 有自己的java.policy 文件,名为opera.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屋!