关闭

java ----- 模拟登陆弹出对话框

945人阅读 评论(0) 收藏 举报
分类:

MyLogin.java

public class Test_Login {
public static void main(String arge[]){
	MyLogin l =new MyLogin("zxl","123");
	l.login();
}
}

Test_Login.java

import javax.swing.JOptionPane;

public class MyLogin {

	private String admin_userName;
	private String admin_passWord;

	public MyLogin() {
		this.admin_userName = "admin";
		this.admin_passWord = "admin";
	}

	public MyLogin(String admin_userName, String admin_passWord) {
		this.admin_userName = admin_userName;
		this.admin_passWord = admin_passWord;
	}

	public String getAdmin_userName() {
		return admin_userName;
	}

	public void setAdmin_userName(String admin_userName) {
		this.admin_userName = admin_userName;
	}

	public String getAdmin_passWord() {
		return admin_passWord;
	}

	public void setAdmin_passWord(String admin_passWord) {
		this.admin_passWord = admin_passWord;
	}

	public void login() {
		String strU = "请输入您用户名:";
		String strP = "请输入您的密码:";
		int num = 0;

		for (int i = 1; i <= 10; i++) {
			if (this.admin_userName.equals(JOptionPane.showInputDialog(strU)) && this.admin_passWord.equals(JOptionPane.showInputDialog(strP))) {
				JOptionPane.showMessageDialog(null, "Success!");
				String choice = JOptionPane.showInputDialog(" 是否修改账户及密码?  (是:  1              否:2)");
				num = 0; // 将记录连续出错的变量清零
				if (choice.equals("1")) {
					this.setAdmin_userName(JOptionPane.showInputDialog(strU));
					JOptionPane.showMessageDialog(null, "账户修改成功! ");
					this.setAdmin_passWord(JOptionPane.showInputDialog(strP));
					JOptionPane.showMessageDialog(null, "密码修改成功!");
					choice = null;
				}

				choice = JOptionPane.showInputDialog(" 是否继续操作?  (是:  1              退出:2)");

				if (choice.equals("1")) {
					continue;
				} else {
					System.exit(0);
				}
			} else {
				num++;
				if (num <= 2) {
					JOptionPane.showMessageDialog(null, "用户名或密码输入错误!请重新输入!");
				} else {
					JOptionPane.showMessageDialog(null, "连续输错用户名或密码,退出系统! ");
					System.exit(0);
				}
			}
		}
	}
}









0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:756806次
    • 积分:12013
    • 等级:
    • 排名:第1262名
    • 原创:420篇
    • 转载:267篇
    • 译文:0篇
    • 评论:37条
    文章分类
    最新评论