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.


Recommended Answers

All 3 Replies

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();

 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>(){

            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();

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.