用户名密码不正确3次java登录表单

时间:2017-04-07 05:41:17

标签: forms login

这是我的代码。它从文本文件中读取并将其与用户输入进行比较。如果输入用户名和密码3次然后做某事,我将如何添加到此。我试过在很多地方放一个柜台,但它不起作用。柜台在哪里?

 Boolean login = false;
  while(read.nextLine() !=null){
    String user = read.next();
    String pass = read.next();
    read.next();
  if(usernameT.getText().equals(user) && 
    passwordT.getText().equals(pass)){
  login = true;
  break;                 
   }
 }
if(login)
new Menu();
else {
JOptionPane.showMessageDialog(null, "Incorrect 
username or password");
usernameT.setText("");
passwordT.setText("");
 }

1 个答案:

答案 0 :(得分:0)

  int counter = 3;
 Boolean login = false;
  while(counter > 0 && read.nextLine() !=null){
    String user = read.next();
    String pass = read.next();
    read.next();
  if(usernameT.getText().equals(user) && 
    passwordT.getText().equals(pass)){
  login = true;
  break;                 
   }
   --counter;
 }