我在主窗口中有个按钮,按钮有个点击事件,当我点按钮事,按钮给我产生另外一个窗口,是NEW出来的。但有个问题当我关闭这个窗口时,主窗口会随之关闭,有什么办法解决?谢谢(关闭窗口是点右上脚那个叉)

解决方案 »

  1.   

    估计你new出来的新窗口里有setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);了,或者是做了什么WindowsClose的监听。
    如果有上述的设置,关闭窗口时就退出程序了。
      

  2.   

    2楼阿宝说的对,肯定是你在关心窗口的事件中用了推出虚拟机的代码
    应该调用dispose()来关闭窗口
      

  3.   

    package net.xiaohai;
    /**
     * @author xiaohai
     *  
     */
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;public class TestMain extends JFrame {
    private JPanel panel = null;
    private JButton button=null;
    private JFrame frame=null;
    public TestMain() {
    super("tital");
    button=new JButton("弹出新窗体");
    frame=new JFrame("new frame");
    frame.setSize(400,300);
    button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
    frame.setVisible(true);
    }});
    panel = new JPanel();
    panel.add(button);
    this.getContentPane().add(panel);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(400, 350);
    this.setLocationRelativeTo(null);
    this.setVisible(true);
    } public static void main(String[] args) {
    new TestMain();
    }
    }
      

  4.   

    谢谢各位 我把APPlication换成JFRAME就没问题了 谢谢