请问为什么这样做会报栈溢出呢

Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
我创建了一个JDialog然后一个按钮加了个监听器

    admin.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                RightChooseView.this.dispose();
                JDialog d=new JDialog();
                new LoginView().show();
                
//                MyFrame frame=new MyFrame("测试");
//                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//                frame.setSize(400,300);
//                frame.setVisible(true);
                
            }        
            
            }
        );

new了一个新的Dialog,show里面就是很简单的几个函数

this.setBounds(300, 200, 800, 400);
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

调试了一下他会一直在setbounds和setvisible之间无限循环...
后来实在不知道怎么办就把第一个窗口设置成Frame用构造函数把Frame写成parent就不报错了...

阅读 720
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题