我正在将 JFrame 转换为小程序并获得安全异常:
C:\prv_workspace_8\DungeonWorldAdventure\bin>appletviewer applet.html
java.security.AccessControlException: access denied ("java.net.SocketPermission"
"www.student.nada.kth.se:80" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:366)
at java.security.AccessController.checkPermission(AccessController.java:
555)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:456)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
at sun.net.www.http.HttpClient.New(HttpClient.java:290)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
它正在尝试从 URL 读取图片:
// Load an image from the net, making sure it has already been
// loaded when the method returns
public Image loadPicture(String imageName) {
Image im = null;
// Load the image from the net
try {
URL imageSource = new URL(
"http://www.student.nada.kth.se/~d99-nro/" + imageName);
try {
im = createImage((ImageProducer) imageSource.getContent());
} catch (IOException e) {
}
} catch (MalformedURLException e) {
}
// Wait to ensure that the image is loaded
MediaTracker imageTracker = new MediaTracker(this);
imageTracker.addImage(im, 0);
try {
imageTracker.waitForID(0);
} catch (InterruptedException e) {
}
return im;
}
知道我怎样才能完成这项工作吗?我需要一个java.policy
文件吗?如果是这样,我如何使这个小程序在网页上工作?