• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextfield

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose we have two textfields in a frame. If we type something in those fields and press enter. How to get the values of those textfields? When I am using getText() method I am able to get only the second text value. I need the values of two textfields.
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to do firstField.getText() and secondField.getText() - perhaps show us your code so that we can help you better.
 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Rachel,
When I am using two getText() methods it is taking only the second value but not the first value. I am giving the code below.

public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if(source instanceof JTextField) {
txtField1 = (JTextField)event.getSource();
answer=(String)MathPackage.matchAnsTxtField1.getText();
txtField2 = (JTextField)event.getSource();
answer = answer+(String)MathPackage.matchAnsTxtField2.getText();
}
}
Here answer is a string and txtField1 and txtField2 are the JTextField objects.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this

reply
    Bookmark Topic Watch Topic
  • New Topic