我写了一个 Java 程序, 它应该打开另一个程序(. jar 文件 ) 。 如果我在程序的主要类中使用这个代码, 所有的操作都是正确的 :
File logFile = new File("./ePaymentUpdater.jar");
Desktop.getDesktop().open(logFile.getCanonicalFile());
//or
Runtime.getRuntime().exec("java -jar ePaymentUpdater.jar");
But if I paste the same code in the event in response to the user clicking a button, it doesn t work as it should: The program seems to run, because it creates a folder like it should be (this code is in the main class of the called program), but it doesn t show the jFrame it should
看来我无法从另一个程序的框架里打开一个框架...
这是我的主班:
package prove_idiote;
import java.awt.Desktop;
import java.io.File;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
// try {
// Runtime.getRuntime().exec("java -jar ePaymentUpdater.jar");
// } catch (Exception e) {
// System.out.println(e);
// }
Tester tester = new Tester();
tester.setVisible(true);
}
}
这是我的按钮事件:
private void ExecuteActionPerformed(java.awt.event.ActionEvent evt) {
try {
JOptionPane.showMessageDialog(null, "before" ,"ATTENZIONE!",JOptionPane.WARNING_MESSAGE);
Runtime.getRuntime().exec("java -jar ePaymentUpdater.jar");
JOptionPane.showMessageDialog(null, "after" ,"ATTENZIONE!",JOptionPane.WARNING_MESSAGE);
} catch (Exception e) {
System.out.println(e);
}
}