• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading from TextField

 
Dominik Pawlocki
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic