Hi,
ive been trying to assign a value to a variable from within the ActionPerformed method, but the value seems to be lost as soon as ActionPerformed method ends. here's the code
public class Log{
private JTextField user = new JTextField(10);
private JPasswordField pass = new JPasswordField(10);
private int usertype=0;
private JPanel panel = new JPanel();
public Log(){
panel.add(user);
panel.add(pass);
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Login logs = new Login(user.getText(), pass.getText());
//this one is querying the database and getting an int value for user type.
usertype = logs.getUsertype();
}
});
//some more codes to add to frame and stuff
}
public int getUserType(){
return usertype;
}
}
When I call the getUserType method, it always returns 0. i've checked if the usertype is assigned any value within the ActionPerformed method and it does. what am i doing wrong here?
thanks in advance