• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating TextFields - Area Calculation  RSS feed

 
Thiago Braun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks, Im currently stuck trying to update a TextField (tf2) to show the area of a circle after it is calculated.

Here is the instructions of the case:

First, employ what you have learned about data encapsulation/hiding. Secondly, fix the applet so that if a user enters a radius and then presses Enter, the area text box will show the true area. You also have a choice about the area text box. You can either make it so that if the user enters an area and presses Enter, the radius text box will show the new radius. Or, you can disable the area text box so data cannot be entered into it.

The area is being corrected calculated, but I tried many different things to get the tf2 TextField updated after the user presses enter and the area is calculated. Since I couldn´t allocate a double on the TextField, I just declared a String named total wich should represent the same value of the area.

What is the most effective and simple way to update that textfield after the area is calculated?

Thanks in advance for any input!!

 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest way is to call the setText() method of your "tf2" variable. You already know how to put the result of the calculation into a String, so then just pass that String to tf2.setText().

I don't understand why your applet has a paint() method... if that was your way of trying to get the data into the second TextField, then take it out.
 
Thiago Braun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:The simplest way is to call the setText() method of your "tf2" variable. You already know how to put the result of the calculation into a String, so then just pass that String to tf2.setText().

I don't understand why your applet has a paint() method... if that was your way of trying to get the data into the second TextField, then take it out.


Thank you very much! I made it. Regarding the paint() method, the exercise involved a previous code wich we had to correct and that method was already there. I guess it´s only purpose was to show a text line with the calculated area after the text fields.

Cheers!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!