0

I need your help. I have 2 applications in Java. I have one of them to invoke from the other. ie the application "A" press a button that opens my application "B" someone has an idea of ​​how you can get to do this?

PS: both applications were developed in Java swing with netbeans.

Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

0

You can have one contain another and have the one being contained set to false, visibilty, then change the visibility. Something like this

public class AFrame extends JFrame {
     private JButton jbt = new JButton("Open Window");
     private BFrame jfrm = new BFrame();

    public class AFrame(){
        add(jbt);
        jfrm.setVisibile(false);
        add(jfrm);

        jbt.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                jfrm.setVisibile(true);
            }
        });
    }
}


public class BFrame extends JFrame {

    public BFrame(){

   }

}

When "Open Window" button is pressed, the BFrame is set to visible, then appears. The AFrame is the starting program, which contains a BFrame

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
0

Try using Desktop.getDesktop().open() function

try {
    Desktop.getDesktop().open(new File("PATH-TO-YOUR-APPLICATION-JAR\\yourapplication.jar"));
} catch (IOException ex) {
    System.out.println(ex.getMessage());
}

Or put the jar file in the class path and invokes its main() method.

Ref:

  1. Launch External Jar through Java Application
  2. Running an external jar file by pressing a JButton
Community
  • 1
  • 1
Sandhu Santhakumar
  • 1,678
  • 1
  • 13
  • 24
0

You can simply do by using dispose() method with frame object of program A to close the program A and setDefaultCloseOperation to HIDE_ON_CLOSE because if you set it to exit_on_close it will terminate and also you need to call the constructor or method of program B before dispose() to start the B program

//in the method were you want to stop the first program and start second program
AFrame.setDefaultCloseOperation(AFrame.HIDE_ON_CLOSE);
new ProgramB(); //calling constructor of class B
AFrame.dispose();