0

I am having two controllers. one is LoginScreenController.java and other is HomeScreenController.java. in loginscreencontroller, i am having button when clicked on that buton it will open homescreen controller. In HomeScreenController i am having TextField and a Ok button.I will fill some data in TextField and click on Ok Button.

Here is my question

After clicking ok button how to get back Textfield data to LoginScreenController.

Thank.

2
Contributors
3
Replies
34
Views
2 Years
Discussion Span
Last Post by SynThiicQ
0

You need something like this in HomeScreenController

Use this in your Button (ActionListener): // YOU CAN USE ANONYMOUS INNER ...

public void ActionPerformed(ActionEvent e){
    if(e.getSource() == but){
        HomeScreenController h = new HomeScreenController(this); 
    }
}

Use this in your HomeScreenController Class

public class HomeScreenController{
    public LoginScreenController main;
    public HomeScreenController(LoginScreenController login){
        this.main = login;
    }
}

you can use variable main to change data from your LoginScreenController

Declare this in your LoginScreenController:
Public String data= "";
Usage in HomeScreenController:
main.data = field.getText();

Edited by SynThiicQ

0
 i have written code like this in button Ok click event getting incompatible type error

 @FXML public void handleOk( final ActionEvent e){

        btnOk.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent t) {
              if(e.getSource() == btnOk){
                    HomeScreenController rpt = new HomeScreenController(this); /* incompatible types: <anonymous EventHandler<ActionEvent>> cannot be converted to LoginScreenController*/

                }
            }

        }
        );

        main.data = txtData.getText();
    }

Edited by narlapavan

0

Is your class "LoginScreenController" extended to JFrame or JPanel?
Maybe that helps? or try this:
Click Here
(Sorry I don't have time to write some test programs to check for myself)

Edited by SynThiicQ

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.