我按下确定按钮时试图关闭窗口。但是当我尝试运行该文件时,它会给我一个StackOverflowError。
这是我的代码:
public class Test1 extends javax.swing.JFrame {
Test1 t = new Test1();
/**
* Creates new form Test1
*/
public Test1() {
initComponents();
}
这是按钮的actionListener。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
t.setVisible(false);
}
这是错误消息,
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at sun.awt.Win32GraphicsConfig.getBounds(Native Method)
at sun.awt.Win32GraphicsConfig.getBounds(Win32GraphicsConfig.java:222)
at java.awt.Window.init(Window.java:505)
at java.awt.Window.<init>(Window.java:537)
at java.awt.Frame.<init>(Frame.java:420)
at java.awt.Frame.<init>(Frame.java:385)
at javax.swing.JFrame.<init>(JFrame.java:189)
at Test1.<init>(Test1.java:11)
at Test1.<init>(Test1.java:13)
at Test1.<init>(Test1.java:13)
at Test1.<init>(Test1.java:13)
at Test1.<init>(Test1.java:13)
at Test1.<init>(Test1.java:13)
at Test1.<init>(Test1.java:13)
...and so on
Test1.java:11引用public class Test1 extends javax.swing.JFrame
而Test1.java:13引用Test1 t = new Test1();
这是什么问题?我该如何解决?