Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Shammikit

How to take user input of one form and assign it to a variable in another form in java?

Recommended Posts

Posted · Original PosterOP

i have a textfield to get user input in my form 1.i want to get the text user inputs into that textfield from that form and assign it to a variable in form2. is this possible?

Link to post
Share on other sites

yes. you can store the input as a string or as another primitive type. Are you using swing?


             ☼

ψ ︿_____︿_ψ_   

Link to post
Share on other sites
Posted · Original PosterOP
3 minutes ago, SCHISCHKA said:

yes. you can store the input as a string or as another primitive type. Are you using swing?

yes

Link to post
Share on other sites

Click on the Text Field. Go to code tab on the right. (By default)

d28dbd25a8c59b65d59ab5a2c7ce3126.png

 

And variable Modifiers. Set this to public.

in the code you will want to create a new object of that frame (contains the text field) ie: NewJFrame mainFrame = new NewJFrame().

then you can get the text through mainFrame.fieldName.getText();

This is might not be the best way but it works.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×