Applet运行时创建 Frame并显示文件对话框,但受到安全限制
编号:QA004039
建立日期: 2001年3月26日 最后修改日期:2001年3月26日
所属类别:
Leo:
操作系统: Winnt4.0 workstation
编程工具: Symantec Cafe4
问题: 想做一个 Applet,运行时创建 Frame并显示文件对话框。但似乎受到安全限制,无法实现。
代码如下:
public class Test extends java.applet.Applet
{
public void init ()
{
frame01 f = new frame01();
}
}
class frame01 extends java.awt.Frame
{
frame01()
{
setVisible(true);
java.awt.FileDialog openFileDialog1 = new
java.awt.FileDialog(this);
openFileDialog1.setVisible(true);
}
}
在 IE 中运行会遇到如下错误:
exception: com.ms.security.SecurityExceptionEx[frame01.]:FileDialog
creation denied.
但在 Cafe 的 AppletViewer中运行,又一切正常,好象没有受到限制,这是怎么回事?上面错误可否通过改变 IE 的设置避免?另外,若class frame01中删除与文件对话框相关的代码,则 Applet 在 IE 中运行正常。如果这是 Applet的限制,这个程序能不能通过其他办法实现?
水平: 一无所知
回答:
Applet运行于沙箱(Applet执行环境)之中,有很严格的安全管理和限制。因此,限制之一就是Applet是不能创建FRAME的。Dialog(和Frame同属于Window的一级子类)等等的也不能创建(FileDialog为Dialog的子类)。很多书中都有Applet限制的更详细介绍。
此问题由chbest回答。
| |
|
|
| |
|
|