• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField

 
nick fox
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have 3 JTextFields A, B and C.
these textfields require integer values to be entered.what i want to do is when a value is entered in textfield A and textfield B i want to automatically calculate the sum of the two values entered and display this value in textfield c.
can i do this??
how??
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would create one TextListener and add it to the first two textfields. In the textValueChanged() method of the TextListener you would get the values from the first two textfields and attempt to cast them into numbers and add them, putting the result in the third text field. If the class that contains the three textfields implements TextListener, or uses an inner class, then you automatically have the references to the textfields. If you use a separate class, you'll have to pass references to the textfields into your TextListener class.
 
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!