I want to get datas from text file ordered like
qwer,qwer,qwer,qwer,wqer
qwer,qwer,qwer,qwer,wqer
But I dont need all data from text file, I just need first 2 data of each line which are username and password.
Other parts are working fine, just need code for this loginB button. usernameT passwordT are textfields that have been already created.
loginB.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
File loginf = new File("login.txt");
try{
Scanner read = new Scanner(loginf);
read.useDelimiter(",");
while(read.nextLine()){
String user = read.next();
String pass = read.next();
read.next();
if(usernameT.getText().equals(user) && passwordT.getText().equals(pass) && admin.isSelected()){
new Menu();
}
}
JOptionPane.showMessageDialog(null, "Incorrect username or password");
usernameT.setText("");
passwordT.setText("");
read.close();
}
catch (FileNotFoundException qwerty){
JOptionPane.showMessageDialog(null, "Can't find a text file");
}
}
});