This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes reading from TextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reading from TextField" Watch "reading from TextField" New topic

reading from TextField

Dominik Pawlocki

Joined: Oct 31, 2001
Posts: 6
How can I read the string entered in my window's TextField or TextArea after the Enter is pressed?
I know how to use the KeyListener to Enter pressing detect,but I don't know how to read this text from my TextField.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

yourTextField.getText() - Returns a String();
You may want to do a little studying of the JAVA API. Have you? It is in there.

Happy Coding,
Gregg Bolinger

GenRocket - Experts at Building Test Data
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
TextField generates an ActionEvent and notifies all of its ActionListener when the RETURN key is typed. So in order to be notified your class should implement the ActionListener interface (i.e. implement the public void actionPerformed(ActionEvent e) method). Then to get what has been typed, you just have to invoke getText() upon your TextField instance and that's it...
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform

[Blog] [Blogroll] [My Reviews] My Linked In
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
Or you can set it as a TextListener and it will fire an event everytime a character is entered in the textfield. Depending on what you need your textfield to do that is.
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud

Michael J Bruesch<br /><i>I code, therefore I am.</i>
I agree. Here's the link:
subject: reading from TextField
It's not a secret anymore!