Java: 如何从不在同一文件但在同一包中的另一个Jframe 打开一个Jframe;

Java: how to open one Jframe from another Jframe which is not in the same file but in the same package;

Java:如何从不在同一文件但在同一包中的另一个Jframe打开一个Jframe;例如:项目包是 test1,它有 2 个 Jframes(home1 和 home2)需要在单击名为 'NEXT'.
的 JButton 时打开第一个框架的第二个框架(home1 的 home2) 谁能帮忙..

您只需调用

即可显示另一个 JFrame
home2 h2 = new home2();
h2.setVisible(true);

所以你的问题是从一个出发框架打开一个新框架?很简单,您只需要实例化一个新的框架对象,如下所示:

JFrame home2 = new Home2(); // don't forget the import since it's a custom made Frame ;)
home2.setVisible(true);

现在您希望在单击 JButton 时完成该操作。为此,您需要使用匿名 class 添加一个 ActionListener 到具有前面代码的 JButton。

jb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            //stuff
        }
    });

参见JButton and the ActionListener的addActionListener()方法。