I have written a Java program that should open another program (which is a .jar file). If I use this code in the main class of my program, all works correctly:
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
It seems that i cannot open a frame from inside the frame of another program...
This is my main class:
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);
}
}
And this is my button event:
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);
}
}