How to call the value of a variable?

Asked

Viewed 143 times

3

How can I call the value of a function variable into another function?

I’m using the jPanel, where I will add a text with:

 jTextArea.append("AREA = " + /*AQUI*/);

Where it says HERE I wanted to put the value of a variable I have in another class:

 public int setCoordenadasB(int x1, int y1, int x2, int y2) {
    p.x = Math.min(x1, x2);
    p.y = Math.min(y1, y2);
    largura = Math.abs(x1-x2);
    altura = Math.abs(y1-y2);
    area = largura * altura;
    return area;
}

It was that "area" that I liked to put in the UP THERE.

The method setCoordenadasB is in a class so-called rectangle and jTextArea is in function main, and the rectangular object was started as:

r = new Retangulo();

1 answer

2


It would be a simple method call, assuming you already have the 2 coordinates in 4 variables coincidentally of the same name within the method main():

jTextArea.append("AREA = " + r.setCoordenadasB(x1, y1, x2, y2));

I put in the Github for future reference.

  • main function rectangular class initiate As these images I hope you can explain to me better, what I wanted to know was how I could make jTextArea.append work.

  • There you are completely changing the question, I answered what was asked. If you want to know something else, you need to ask another question. This new code has no relation to what was asked. I can only answer what was asked, there’s no way I can guess what you really wanted.

  • I am sorry then, I will ask another question, I may have explained myself badly. .

  • I have already asked a new question, this time with prints of my code to facilitate the understanding of who can help me, thank you for the advice. New Topic: Topical

Browser other questions tagged

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