如何使用 JButton 转到另一个 java 文件(另一个 class)

How to use JButton to go to another java file (another class)

我有两个 java classes:Menu 和 PMotion。菜单 class 包含一个 JButton,如下所示。当按下这个 JButton 时,我希望它转到 PMotion.java

如何实现?

Menu.java

        public void actionPerformed(ActionEvent e) {
// Here I need to write the code which takes the user to PMotion.java
}

下面是有关如何使用 JButton 打开新 JFrame 的示例。

    JButton show = new JButton("show Form2");
    show.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            PMotion pMotion = new PMotion();
            pMotion.setVisibile(true); // Show pMotion form
            Form1.this.setVisible(false); // Hide current form where Form1 is your current JFrame class
        }

    });