I can’t write in Jtextarea

Asked

Viewed 84 times

0

have the class:

import javax.swing.JTextArea;

public class Semantico {

private String tipo;
private String variavel;


public void verificaSem(String stipo, String svariavel, JTextArea txtSemantico){

    this.tipo = stipo;
    this.variavel = svariavel;

    String tipo2 = "int";

    if (tipo==tipo2){

        txtSemantico.setText(tipo);
    }


}




}

This txtSemantico is in my main class, and I would like to write the contents of the variable type which is "int" if it is equal to the contents of Tipo2 which is also "int". The point is that it does not write. Detail, if I take the If condition and leave what is inside the If, it works. Thank you.

  • Probably the values are not equal, so do not write, it is a logic problem in the case. Debug the code and see if it’s really coming in the same. Tip: use equals to compare strings and not ==

1 answer

0

  • 1

    Working works, just not recommended. This is not quite a logic error, and yes, semantic.

  • @diegofm What would be the recommended way to compare two String ?

  • Using equals, I meant to use the sign == to compare strings. It may work in many cases, but the equals is what was made for this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.