How do I Prompt the user to enter a password before entering the main program?

前端 未结 3 1353
庸人自扰
庸人自扰 2020-12-21 02:16

What I need to do is to prompt the user with a username and password (authentication is done locally) and if it checks out, the user would then be able to access the main pr

3条回答
  •  醉梦人生
    2020-12-21 02:59

          String userName = userNameTF.getText();
          String userPassword = userPasswordPF.getText();
            if(userName.equals("xian") && userPassword.equals("1234"))
            {
              JOptionPane.showMessageDialog(null,"Login successful!","Message",JOptionPane.INFORMATION_MESSAGE); 
              // place your main class here... example: new L7();
            }
            else 
            {
               JOptionPane.showMessageDialog(null,"Invalid username and password","Message",JOptionPane.ERROR_MESSAGE); 
               userNameTF.setText("");
               userPasswordPF.setText("");                       
            }  
    

提交回复
热议问题