The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

JTextField getting text values

Hey guys, I'm trying to make a simple JFrame where the user will input information and the information will then be printed out. The problem is, I have no idea how to acquire the string which the user input. I've tried many different things and the main problem seems to be that I can't add an ActionListener to my JTextField for some reason...

Re: JTextField getting text values

I don't see where any actionListeners are added to the components. In addition, if you wish to add an ActionListener to a JTextField and filter those events via the action command, you should set the ActionCommand of the JTextField.

Re: JTextField getting text values

Originally Posted by The_Mexican

And it comes up with the error "Cannot use this in a static context" I understand what the means but there's just no other way to do it.

That information would have been helpful in your original post. this in a static function is out of context because there is not this. Create an instance of the class, then add that as the action listener.