I'm writing a program for exemplary reasons that is basically two text fields, one for a username, and one for a password. the way its written is asking testing for what is inputed into the text fields if its equal to a "valid" username and password. if it is, a variable representing that is set equal to 1. there is another if statement asking if the actionevent.getsource is equal to the name of the textfield. the issue I had was that when I ran the program, it seemed to only test for the first condition, so I got the same result from the program regardless of what I input into the text field.
The Code
Main class:
Secondary or sub class:
*the code originaly was written "eve.getSource() ==" but I changed that to see if it would resolve the issue with no avail. With it written this way, the program does nothing upon entering the text and pressing enter. Currently, there is nothing written to change the variable "val" to 1 to show that the username is valid. I did this because I can't figure out how I would go about doing this.import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTextField; public class log extends JFrame{ JTextField mess1; JTextField un; public log(){ super("Sign In"); setLayout(new FlowLayout()); mess1 = new JTextField("Enter your name here:"); mess1.setEditable(false); add(mess1); un = new JTextField(" "); add(un); thehandler asdf = new thehandler(); mess1.addActionListener(asdf); un.addActionListener(asdf); } class thehandler implements ActionListener{ String s1; int val = 0; public void actionPerformed(ActionEvent eve){ if(eve.getSource().equals(un) && val == 1){ s1=String.format("Logging in, please wait...", eve.getActionCommand()); JOptionPane.showMessageDialog(null, s1); } else if(eve.getSource().equals(un) && val != 1) s1=String.format("Your username or password is incorrect.", s1); } } }