File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes getting jTextField input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getting jTextField input" Watch "getting jTextField input" New topic

getting jTextField input

Ah Ling

Joined: Dec 28, 2009
Posts: 12
Good day to all!

I met one problem while doing my project.
I have two classes.
One class is like a form which will take in input from the user using jTextField.
Another class is like a summary which will display what the user had entered in the form.
Can I display the input entered in the form at my latter class in jLabel or jTextField?

I tried the methods that I have found online but it does not help.
Any kind soul can provide me a simple example? I'll try to figure it myself.
Ah Ling

Joined: Dec 28, 2009
Posts: 12
So sorry for your time!
I have got it right already!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10825

glitter Air wrote:

Welcome to the Ranch.
Please check your private messages for an important administrative matter

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Piyush Patel
Ranch Hand

Joined: Feb 24, 2009
Posts: 127

create static mathod that returns jTextField value . (make JTextField Object Static as well) .
then call,

String val=ClassName.getJTextFieldVal();

which gives you uour jTextField value in Another class.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

Yeah, don't. Static component fields are just about never a good idea. Instead, make it an instance field, make the method non-static and just use a reference to an existing object to call the method on.

How To Ask Questions How To Answer Questions
Ah Ling

Joined: Dec 28, 2009
Posts: 12
Ok thanks peeps!
Problem solved already!
I agree. Here's the link:
subject: getting jTextField input
It's not a secret anymore!