title: Comparing username and password to data from text file using java
body: <p>I want to get datas from text file ordered like </p>
  
  <pre><code>qwer,qwer,qwer,qwer,wqer
  qwer,qwer,qwer,qwer,wqer  
  </code></pre>
  
  <p>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 <code>loginB</code> button. <code>usernameT</code> <code>passwordT</code> are textfields that have been already created.</p>
  
  <pre><code>    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) &amp;&amp; passwordT.getText().equals(pass) &amp;&amp; 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");
              }
         }
      });
  </code></pre>