JFrame 关闭按钮



我有一个Jframe窗口,里面有一个按钮。通过单击该按钮,它将打开一个新的 JFrame 窗口。但是当我关闭这个窗口时,它会自动关闭第一个带有按钮的 Jframe 窗口。如何防止第一个 Jframe 窗口在关闭第二个窗口时关闭?

public static void main (String[] args){
        JFrame frame = new JFrame("Test");
        frame.setVisible(true);
        frame.setSize(500,500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton button = new JButton("Test");

        button.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                new SView().gui();
            }
        });

        JPanel panel = new JPanel();
        GridBagLayout gridbag = new GridBagLayout();
        panel.setLayout(gridbag);
        panel.add(button);
        panel.setBackground(new Color(156, 93, 82));
        frame.add(panel, BorderLayout.CENTER);

不要打电话

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

最新更新