-1

此类从 CreateAccount 类获取输入,然后将其存储在名为 users 的数组丢失中

import java.util.ArrayList;

public class User {
   public static ArrayList<User> users = new ArrayList<>();
   public String username, password;
   public User(){
    
       this.username = "johnd";
       this.password = "johnd";
   
       User newUser = new User(this.username, this.password);
       users.add(newUser);
   }

   public User( String uname,String pword){
       this.username = uname;
       this.password = pword;
   
       User newUser = new User( this.username, this.password);
       users.add(newUser);
   }
};

此类从用户那里获取输入并将其传递给“用户”类和数组列表“用户”

public class CreateAccount {
   String user1, pass1;
    //get text from user 
    user1 = username.getText(); 
    pass1 = password.getText();
   //pass to "User" class and "user" arraylist
   User newUser = new User(user1, pass1);
   newUser.users.add(newUser);
}

这个类应该检查数组列表中具有相同索引的用户名和密码,并在控制台中显示“成功登录”

public class Login {
for (int i = 0; i < 10; i++){
    
        String user,pass;
    
         String[] usernames = {"bereket6244"};
         String[] passwords = {"bereket6244"};
        // get text from user 
        user = username.getText();
        pass = password.getText();
    
        if (usernames[i].equals(user) && passwords[i].equals(pass)){
            System.out.println("successful login");
        }
        else {
            JOptionPane.showMessageDialog(null, "Username and Password don't match");
        } 
        }
}
4

0 回答 0