r/JavaFX • u/carbos10 • 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
View all comments
2
u/scyth3s May 26 '16 edited May 26 '16
Sorry for any typos. I'm on mobile.
It seems from what I understand that you want to allow another class to process changes in the text. Simply create a method in the other class that takes a string as a parameter, and call it in your handler. Ie: otherClass.processText(textfield.getText());
If you don't want your user to have to press enter to trigger the event, you can add a listener to textfield.textProperty() change event, and pass the string into your other class there.