基本上我有一个需要加载 Applet 的 JFrame。小程序需要是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();
}
获取目录:
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;
}