title: How do I put 3 login tries before the programs exits by itself?
body: <p>Whenever the user got the wrong user or password for 3 tries the program will have a pop-up message window with &quot;You got incorrect username/password, this program will exit&quot; then the program will exit by itself. Can you guys help me? Thank you in advance!
  I tried looping with do-while, but it just pops up three logging error window.</p>
  <pre><code>public void actionPerformed(ActionEvent ae) {
      String user = tf1.getText();
      String password = tf2.getText();
  
      String[] users = { &quot;user1&quot;, &quot;user2&quot;, &quot;user3&quot;, &quot;user&quot;, &quot;JDjwa89duaJd8u&amp;DuwADUu@A*Uj8dju&quot; };
      String[] pass = { &quot;pass1&quot;, &quot;pass2&quot;, &quot;pass3&quot;, &quot;pass4&quot;, &quot;djoiaw87798duyA*(dywayd*(&amp;d8a7D&quot; };
      int ctr = 1;
  
      if (tf1.getText() != null &amp;&amp; tf2.getText() != null) {
  
          if (user.equals(users[0]) &amp;&amp; password.equals(pass[0])) {
              System.out.println(&quot;Hello: &quot; + users[0]);
              System.out.println(&quot;Login Succesful!&quot;);
          }
  
          if (user.equals(users[1]) &amp;&amp; password.equals(pass[1])) {
              System.out.println(&quot;Hello: &quot; + users[1]);
              System.out.println(&quot;Login Succesful!&quot;);
          }
  
          if (user.equals(users[2]) &amp;&amp; password.equals(pass[2])) {
              System.out.println(&quot;Hello: &quot; + users[2]);
              System.out.println(&quot;Login Succesful!&quot;);
          }
  
          if (user.equals(users[3]) &amp;&amp; password.equals(pass[3])) {
              System.out.println(&quot;Hello: &quot; + users[3]);
              System.out.println(&quot;Login Succesful!&quot;);
  
          }
  
          if (user.equals(&quot;&quot;) &amp;&amp; password.equals(&quot;&quot;)) {
              JOptionPane.showMessageDialog(null, &quot;Please type in your username/password.&quot;, &quot;Login Error&quot;, JOptionPane.ERROR_MESSAGE);
          }
      } else if (tf1.getText() != users[4] &amp;&amp; tf2.getText() != pass[4]) {
  
          JOptionPane.showMessageDialog(null, &quot;Incorrect username/password&quot;, &quot;Login Error&quot;, JOptionPane.ERROR_MESSAGE);
          ctr++;
      }
  
  }
  </code></pre>