I'm very new to Java and I'm making a gui that has a "register" button and "check if ID is available button".
The register button is suppossed to add the ID, Password, Username to the txt file. As you can see in the image below the register is working well, The "check if ID is available button" is not. When I register with "ID: qwe PW: 123 Username:abc", "qwe 123 abc " is added to my txt file. When I type in "qwe" in ID again and press the "ID available check" button it shows me it's available. But when I type in "qwe 123 abc " it says it's not available.
I think it has something to do with the readLine but I have no idea how to make it read in seperate words. Is there anything I can add to make it read the line in seperate words and make it show it's not available when I type in the same ID and press check ID button again?
This is the check available ID button code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BufferedReader br = null;
String checkid = jTextField1.getText();
String readid = null;
var allid = new ArrayList<String>();
try{
br = new BufferedReader(new FileReader("member.txt"));
while((readid=br.readLine()) != null){
allid.add(readid);
}
br.close();
if(allid.contains(checkid)){
JOptionPane.showMessageDialog(null, "not available");
}else{
JOptionPane.showMessageDialog(null, "available");
}
}catch (Exception ex) {
}
}