我有以下代码在新进程中启动类:
public final class JavaProcess {
private JavaProcess() {}
public static int exec(Class klass) throws IOException, InterruptedException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = klass.getCanonicalName();
ProcessBuilder builder = new ProcessBuilder(javaBin, "-cp", classpath, className);
Process process = builder.start();
process.waitFor();
return process.exitValue();
}
}
我像这样使用它:
public static void main(String[] args) throws IOException, InterruptedException {
CustomFrame F = new CustomFrame();
System.out.println(JavaProcess.exec(MyApplet.class)); //Start an applet in a separate JVM.
}
如何将该小程序添加到我的 JFrame?我尝试了以下方法:
public static void main(String args[]) throws IOException {
CApplet CP = new CApplet(null, false, 765, 503);
//Perhaps serialize it.
ObjectOutputStream oos = new ObjectOutputStream(System.out);
oos.writeObject(CP);
oos.close();
}
并读取序列化对象并将其添加到我的 JFrame 中?我怎样才能做到这一点?