title: Two if statement is executed in java code
body: <p>Im currently trying to do a validation for staff login form. but i realized in my validation output that whenever i enter a value to the username text field, it still pops up the message "please enter your username" then the "invalid credentials"message box. Here is my code down below : </p>
  
  <pre><code> String username = usernameTxt.getText();
      String password = passwordTxt.getText();
  
  
      if  (username.contains(""))
    {
          JOptionPane.showMessageDialog(null,"Please Enter Your Username Credentials.");
      }
      else  if (password.contains (""))
    {
          JOptionPane.showMessageDialog(null,"Please Enter Your Password Credentials.");
      } 
     else if (password.contains ("") &amp;&amp; (username.contains("")))
    {
          JOptionPane.showMessageDialog(null,"Please Enter Your Login Credentials.");
      }
     if ((username.contains("staff") &amp;&amp; password.contains ("pass")))
  
      {
          JOptionPane.showMessageDialog(null,"Login Successfull","Success",JOptionPane.INFORMATION_MESSAGE);
          passwordTxt.setText(null);
          usernameTxt.setText(null);
          staffdashboard sd = new staffdashboard();
          sd.setVisible(true);
          this.setVisible(false);   
      }    
      else  
      {
          JOptionPane.showMessageDialog(null,"Invalid Login Details","Login Error",JOptionPane.ERROR_MESSAGE);
          passwordTxt.setText(null);
          usernameTxt.setText(null);
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vr8Du.png" rel="nofollow noreferrer">enter user message box </a>
  <a href="https://i.stack.imgur.com/2jlh9.png" rel="nofollow noreferrer">invalid login details message box </a></p>
  
  <p>What am i missing out and how do stop the form to output 2 message box at once?</p>