title: Trying to make a login page, I am stuck! [java]
body: <p>Here is my code and what I want to do is, when the login button is pressed, I would like it to check the password and text fields for the right password(found in the if statement). I need help on what to do to get the input from the text and password fields. When I run the code, it skips right to the else statement and does the code in there, I want it to do the if statement as I have entered the right username and password. I was trying to figure out how to get input from the text fields but I don't know how to. I would appreciate some help, thank you.</p>
  <pre><code>    import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.GridLayout;
      import java.awt.TextArea;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.MouseListener;
  
      import javax.swing.BorderFactory;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JPasswordField;
      import javax.swing.JTextField;
  
      public class GUI_2 implements ActionListener {
  
          private JLabel PassLabel;
          private JFrame frame;
          private JButton enterButton;
          private JLabel UserLabel;
          private JLabel label;
          private JPanel panel;
          private JFrame Incorrect;
          private JTextField password;
          private JTextField username;
          private String rightPassword;
          private String rightUsername;
          private String passwordInput;
          private String usernameInput;
          private JButton UsernameEnter;
          private JButton PasswordEnter;
          private final static String newline = &quot;\n&quot;;
          private TextArea textArea;
  
  
          public GUI_2()
          {
              PassLabel = new JLabel(&quot;Enter Password:&quot;);
              password = new JPasswordField(11);
              UserLabel = new JLabel(&quot;Enter Username:&quot;);
              username = new JTextField(11);
              enterButton = new JButton(&quot;Login&quot;);
              label = new JLabel(&quot;Access&quot;);
              UsernameEnter = new JButton(&quot;Enter&quot;);
              PasswordEnter = new JButton(&quot;Enter&quot;);
              frame = new JFrame();
              panel = new JPanel();
              Incorrect = new JFrame();
              enterButton.addActionListener(this);
      
              panel.setBorder(BorderFactory.createEmptyBorder(200,200,60,300));
              panel.setLayout(new GridLayout(5, 5));
              panel.add(UserLabel);
              panel.add(username);
              panel.add(PassLabel);
              panel.add(password);
              panel.add(label);
              panel.add(enterButton);
      
              frame.add(panel, BorderLayout.CENTER);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setTitle(&quot;Password Login&quot;);
              frame.pack();
              frame.setVisible(true);
      
      
          }
  
  
          public static void main(String[] args) {
              new GUI_2();
              // TODO Auto-generated method stub
  
          }
  
  
  
  
  
  
      public void actionPerformed(ActionEvent arg0)
      {
      
      
          if (passwordInput == &quot;password&quot; &amp;&amp; usernameInput == &quot;harry&quot;)
          {
              frame.setTitle(&quot;Success&quot;);
              label.setForeground(Color.green);
              label.setText(&quot;Access granted&quot;);
          }
          else
          {
              frame.setTitle(&quot;Access Denied&quot;);
              label.setForeground(Color.red);
              label.setText(&quot;Access Denied&quot;);
          }
      }
      }
  </code></pre>