0

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?

2
  • do you have an initial piece of code Commented May 9, 2015 at 3:48
  • If you wish to run the new code in the same JRE as the one running the button, establish an URLClassLoader to the new Java app. then load and use the classes as needed. Commented May 9, 2015 at 3:57

1 Answer 1

0

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) {

          }
      }
  });
Sign up to request clarification or add additional context in comments.

2 Comments

See When Runtime.exec() won't for many good tips on creating and handling a process correctly. Then ignore it refers to exec and use a ProcessBuilder to create the process.
Huh.. I voted down before I even saw } catch (IOException ex) { } ..can I have another turn? That should be } catch (IOException ex) { ex.printStackTrace(); }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.