基本上我有一个需要加载Applet的JFrame。 applet需要是Jar文件中的特定类,我有以下代码:
public Applet load() throws Exception {
URL[] urls = new URL[] {new URL("file:"+getDirectory()+"file.jar")};
URLClassLoader classLoader = new URLClassLoader(urls);
Class client = classLoader.loadClass("client");
return (Applet) client.newInstance();
}
getDirectory:
public static String getDirectory(){
String dir = System.getProperty("user.home");
return dir + File.separator + "Directory" + File.seperator;
}
但是当小程序加载时,它什么都不做。
我也尝试过:
public Applet get() throws Exception {
Applet game = load();
game.setLayout(new BorderLayout(0, 0));
game.setBackground(Color.black);
game.setStub(this);
game.init();
game.start();
return game;
}