How to print an array in a JtextField in Java Swing?

0

I want to print an array that generates it in the following form

public String buscar(){
    numero = (int) (Math.random() * 3) + 1;
    palabra = libreria[numero];
    return palabra;
}

public void cambiar(){
    for(int i = 0 ; i < palabra.length() ; i++ ){
        aux [i] = "_";
    }
}

What I want is to change the word to a "_" is for a game of hangman but to print it in a JTextField with display.setText(aux.toString()); [Ljava.lang.String; @

    
asked by Ricardo Jesus Jarquin Perez 26.02.2018 в 21:40
source

1 answer

1

To do what you want you must go through the arrangement to concatenate each element of this to a variable of type String , or better, use a StringBuilder as I show you below.

StringBuilder builder = new StringBuilder();
for(int i = 0 ; i < palabra.length() ; i++ ){
    builder.appande(aux[i]);
}

Now if you can do something like this: display.setText(builder.toString());

    
answered by 26.02.2018 в 21:48