为什么不能实现输入密码 3 次错误后不能自动关闭页面
package framd;import java.awt.*;
import java.awt.event.*;
public class frame_test2
{
public static void main(String args[])
{
qwe t1 = new qwe();
t1.init();
}
}
class qwe
{
private static int i;
private String st="123456";
private Frame fr;
private MenuBar mb;
private Menu m;
private MenuItem mi;
private Button bt,bt2;
private TextField tf1,tf2;
private TextArea ta;
public void init()
{
fr = new Frame ();
mb = new MenuBar();
fr.setBounds(400, 400,400, 400);
fr.setLayout(new FlowLayout());
tf1 = new TextField("您只有三次输入密码的机会",30);
bt2 = new Button("确定");
fr.add(tf1);
fr.add(bt2);
fr.setVisible(true);
myevent();
}
public void init2()
{
bt = new Button("你好");
tf1 = new TextField("不可编辑的文本框",30);
tf2 = new TextField("可编辑的文本框",30);
tf1.setEditable(false);
fr.add(tf1);
fr.add(tf2);
fr.add(bt);
fr.setVisible(true);
}
public void myevent()
{
//进行密码的判断
bt2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for(i=0;i<3;i++)
{
if(tf1.getText().equals(st))
{
fr.removeAll();
init2();
}
else
{
if(i>3)
{
fr.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
else
{
tf1.setText("");
}
}
}
}
});
fr.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}