Java 用JApplet获取图像

Java 用JApplet获取图像,java,html,swing,japplet,imageicon,Java,Html,Swing,Japplet,Imageicon,我有以下可运行代码: import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JApplet; import javax.swing.JPanel; public class Main extends JApplet{ public static Main instance; public static ImageIcon getImage(String fname){

我有以下可运行代码:

import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JPanel;


public class Main extends JApplet{
    public static Main instance;
    public static ImageIcon getImage(String fname){
        return new ImageIcon(instance.getImage(instance.getDocumentBase(),fname));
    }
    public void init(){
        instance = this;
        @SuppressWarnings("serial")
        JPanel p = new JPanel(){
            ImageIcon img = getImage("YES.png");
            public void paintComponent(Graphics g){
                super.paintComponent(g);
                if(img != null)
                g.drawImage(img.getImage(),0,0,getWidth(),getHeight(),null);
            }
        };
        this.setContentPane(p);
    }
}
当我在eclipse中运行这个程序时,它就工作了。但当我在google chrome上使用以下html文档运行它时:

<html>
<head>
    <title>VResponse</title>
    <style type="text/css">
        body{
            background-color:white;
            padding:1%;
        }
    </style>
</head>
<body>
<div>
<applet code="Main.class" width="800" height="600" />
</div>
</body>
</html>

VResponse
身体{
背景色:白色;
填充:1%;
}
/---=带有错误japplet的网页

您应该可以在此处下载整个文件夹:

SRC代码如下:
这个问题与安全有关。当我对小程序进行签名,并在清单中给它一个好的权限节点时,它就消除了错误

我在清单中添加了以下内容:

Permissions: all-permissions
Codebase: *.hobogames.atspace.cc
Application-Name: GreenCube
我在命令提示符下使用以下命令对其进行了签名:

cd homeDirectory
keytool -genkey -alias alias -keystore .keystore

cd directoryOfJar
jarsigner jar-file alias
其中别名通常是您的名字


解决了一些安全问题,,并允许我加载映像。

您能发布堆栈跟踪吗?在Chrome中看到的地址是什么?@MrD我不知道如何获取堆栈跟踪,如果在eclipse中运行时没有错误。@AndrewThompsonfile:///C:/Users/Chase/Dropbox/ALL_PROJECTS/Other%20Projects/Basic/bin/index.html 或者:确保图像可以从html文件的位置(根据示例,它应位于同一目录中)
cd homeDirectory
keytool -genkey -alias alias -keystore .keystore

cd directoryOfJar
jarsigner jar-file alias