• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i get one value from a JTextField to show in another classes JTextfield  RSS feed

 
M Gerber
Greenhorn
Posts: 29
Chrome Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want the text that the user inputs into the JTextField in the user input panel to be what shows up in the JTextField in the totals panel.


Totals panel



I know that I will need to take advantage of the get and set methods, couLd i get an example of this? I amd confused in how to write the code.
 
K. Tsang
Bartender
Posts: 3630
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not having read the code. Question is can the 2 text field communicate with each other? Or are they aware of each other existence?

If they can, meaning they are in the same class (inner, anonymous or not). Else they can't.

If they can't, is there say a static method to the text field object so that you can get/set the value?

Point to note: if the 2 components (text fields) are in the same panel then they should be in the same class.
 
Jim Ronholm
Greenhorn
Posts: 21
3
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have a few things to fix up first. Generally speaking things called "get" will return a value - that's what "get" means. Things called "set" will generally accept a value and then use it to assign a value to a property.

Next - did you really want two different JFrames? That is the equivalent of two different windows. Your question refers to "panel" - maybe UserInput and Totals should be extending some sort of Panel (hint: JPanel) instead of JFrame?

But after that you need to think about when do you want to take the value from the one and put it in the other? By that I mean what event do you want to use to cause the value be copied? Possibilities include: as the user types, when s/he clicks another control, when s/he presses enter, every so often (timer).

At a guess - since you have an ActionListener - you intended to do it when s/he presses enter in the textfield. At that point, do you have a reference to the destination panel?

I think you may need to spend a little more time thinking through the logic before you try to fix the code.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!