I have java program with interface created using Java Swing. The interface contains a JButton. I want to add Action to that button so that it should execute another Java program which I specify.
How to do that?
Try this:
yourButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Process proc = Runtime.getRuntime().exec("java -jar A.jar");
} catch (IOException ex) {
}
}
});
exec and use a ProcessBuilder to create the process.} catch (IOException ex) { } ..can I have another turn? That should be } catch (IOException ex) { ex.printStackTrace(); }
URLClassLoaderto the new Java app. then load and use the classes as needed.