Java GUI 界面跳转如何实现最好有例子代码

解决方案 »

  1.   

    setVisable(false)前一个页面另一个页面setVisable(true)
      

  2.   

    不知道你想跳转什么,是不是点击一个按钮弹出另一个窗口呢
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;public class MyFrame extends JFrame {
    private JButton button; public MyFrame() {
    button = new JButton("show");
    button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // 打开另一个窗口
    new AnotherFrame();
    }
    });
    this.add(button);
    } public static void main(String[] args) {
    MyFrame frame = new MyFrame();
    frame.setTitle("Test");
    frame.setSize(400, 300);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }// 另一个窗口
    class AnotherFrame extends JFrame {
    public AnotherFrame() {
    setSize(400, 300);
    setVisible(true);
    }
    }
      

  3.   


    明白了,原来就是在new一个对象啊!