How can I store the characters entered in a JTextArea in a variable?

0

I am learning java and I have seen a problem in creating a login, I want to store the data that a user enters in a JTextArea in a variable, but it is not stored, and when I give a button that compares it with a name that I have put (since I still do not handle with databases) I have tried it in several ways and I can not do it, I do not know if it's better with JTextArea you can not and you would have to use something else. Thanks in advance

I echo:

JTextArea areausuario = new JTextArea("", 1, 16);

String ususario=areausuario.getText();

//Comprobar que hay en la variable
System.out.println(usuario);
    
asked by Acoidan Negrín Socorro 20.12.2017 в 16:11
source

1 answer

0

The error I had was that I put a button to confirm if the entered user was correct, but store what was in the JTextArea, before the ActionListener, which happens, when doing that, the variable in which the entered text was saved the user was empty and pressing the button did not change its value.

    class EventoConfirmar implements ActionListener {


    public void actionPerformed(ActionEvent e) {

        //Parte que tenia fuera del ActionListener 
        usuariointro=areausuario.getText().trim();

        if (usuariointro.equals(usuario1.getNombreUsuario())){

            System.out.println("Uusario correcto");

        }else {

            System.out.println("Usuario incorrecto");

        }

    }

}
    
answered by 20.12.2017 в 21:16