| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 626 人关注过本帖
标题:为什么不能实现输入密码 3 次错误后不能自动关闭页面
只看楼主 加入收藏
qwe885167759
Rank: 4
等 级:业余侠客
威 望:5
帖 子:148
专家分:259
注 册:2013-3-12
结帖率:72.22%
收藏
 问题点数:0 回复次数:3 
为什么不能实现输入密码 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);
            }
        });
    }
   
}
搜索更多相关主题的帖子: private package 输入密码 public import 
2014-05-14 09:52
qwe885167759
Rank: 4
等 级:业余侠客
威 望:5
帖 子:148
专家分:259
注 册:2013-3-12
收藏
得分:0 
想了一会后,自己解决了,这是代码:
package frame;

import java.awt.*;
import java.awt.event.*;

//import javax.swing.JTextField;
public class frame_test2
{
    public static void main(String args[])
    {
        qwe t1 = new qwe();
        t1.init();
    }
}

class qwe
{
   private int i=0;
   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("你好");
       fr.add(bt);
       fr.setVisible(true);
   }
    public void myevent()
    {
        
            bt2.addActionListener(new ActionListener()
            {   
                public void actionPerformed(ActionEvent e)
                {
                    
                    if(tf1.getText().equals(st))
                    {
                        fr.removeAll();
                        init2();   
                    }
                    else
                    {
                        tf1.setText("");
                    }
                    
                    if(i==3)
                    {
                        fr.dispose();
                    }
                    i++;
                 
        }
            });
        fr.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
    }
   
}

我本楚狂人,凤歌笑孔丘
2014-05-14 22:18
love云彩
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:青藏高原
等 级:贵宾
威 望:53
帖 子:3663
专家分:11416
注 册:2012-11-17
收藏
得分:0 
给自己多一点点时间,也许问题就解决了

思考赐予新生,时间在于定义
2014-05-14 23:15
qwe885167759
Rank: 4
等 级:业余侠客
威 望:5
帖 子:148
专家分:259
注 册:2013-3-12
收藏
得分:0 
嗯嗯
谢谢

我本楚狂人,凤歌笑孔丘
2014-05-15 23:20
快速回复:为什么不能实现输入密码 3 次错误后不能自动关闭页面
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054245 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved