Reputation: 103
I have two java classes. say class Login and class Details. Class Login data Members : String uname,passwd. I have created JFrame in class Login and it has two text fields : uname and password with a submit button. I'm getting the values of uname n passwd and assigning to the data members. On click of the button I need to send (uname,passwd)Login object to class Details.
submit.addActionListener (new Details(this));
But in Details class I'm not able to retrieve the values of Login object. Is this the right way ? Can anyone explain the proper steps ? Thanks in advance
P.S
I'm new to JFrame. My question might sound silly
Upvotes: 1
Views: 298
Reputation: 347184
"Is this the right way ?" probably not. You should use a modal JDialog
instead of JFrame
, this will allow the code execution to be stopped at the point the dialog is made visible and will only resume after it is closed, meaning that when execution resumes, you can inspect the values generated by the dialog.
I'd also make use of some kind of model, which you can provide to the dialog, it would then fill it out with the details it collects and based on the return result from the dialog, you would then be able to use those values in the way you want to
Have a look at How to Make Dialogs for more details
Upvotes: 3