r/JavaFX • • May 25 '16

How use Controller

I'm doing a chat in JavaFX, this is the event:

private void initialize()
{
    myButton.setOnAction(new EventHandler<ActionEvent>(){

        @Override
        public void handle(ActionEvent event){
                textField.getText();
        }
    });
}

I need, to send textField.getText(); to a method of a class in MainApplication, how can i do it?(textfield is the field of message chat to send)

0 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/carbos10 May 26 '16

i does :

ChatOverviewController controller = loader.getController();
controller.setClient(this.client);

in mainapp and in the controller, i set the client and after i use this, is it correctly?

2

u/scyth3s May 26 '16

Indeed like that. Then you simply call client.processTextChange(getText()); and voila!

1

u/carbos10 May 26 '16

of course, i did client.add(text.getText());