Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从另一个应用程序打开java应用程序_Java_Swing_Netbeans_Call - Fatal编程技术网

从另一个应用程序打开java应用程序

从另一个应用程序打开java应用程序,java,swing,netbeans,call,Java,Swing,Netbeans,Call,我需要你的帮助。我有两个Java应用程序。我有一个可以从另一个调用。ie应用程序“A”按下按钮打开我的应用程序“B” 有人想到​​你怎么能做到这一点 PS:这两个应用程序都是在Java swing中使用netbeans开发的。您可以让其中一个包含另一个,并将其中一个设置为false、visibility,然后更改可见性。像这样的 public class AFrame extends JFrame { private JButton jbt = new JButton("Open Wi

我需要你的帮助。我有两个Java应用程序。我有一个可以从另一个调用。ie应用程序“A”按下按钮打开我的应用程序“B” 有人想到​​你怎么能做到这一点


PS:这两个应用程序都是在Java swing中使用netbeans开发的。

您可以让其中一个包含另一个,并将其中一个设置为false、visibility,然后更改可见性。像这样的

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

   }

}
按下“打开窗口”按钮时,
BFrame
设置为可见,然后出现。
AFrame
是启动程序,它包含一个
BFrame

尝试使用函数

try {
    Desktop.getDesktop().open(new File("PATH-TO-YOUR-APPLICATION-JAR\\yourapplication.jar"));
} catch (IOException ex) {
    System.out.println(ex.getMessage());
}
或者将jar文件放入类路径并调用其main()方法

Ref:


  • 只需对程序A的frame对象使用dispose()方法关闭程序A,并使用setDefaultCloseOperation隐藏\u ON\u close,因为如果将其设置为exit\u ON\u close,它将终止,并且需要在dispose()之前调用程序B的构造函数或方法来启动B程序

    //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();
    

    您希望它们在JVM的上下文中执行,还是应用程序“B”应该在它自己的JVM中启动?请参见此。