W klasie A mam TextArea textArea i Button przycisk, chciałbym zrobić obsługę przycisku w klasie B, na razie wiem jak sprawdzić czy przycisk został kliknięty, ale jak mogę pobrać tekst z textArea do Stringa? normalnie zrobiłbym to "String tekst= textArea.getText();", ale jak dostać się z klasy B do textArea w klasie A?
//klasa A
B ctrl = new B();
TextArea textArea= new TextArea();
textArea.setMaxHeight(100);
grid.add(textArea, 0, 1);
Button przycisk= new Button("Przycisk");
przycisk.setOnAction(ctrl.getHandler());
/////////////////////////////////////////////////////
//klasa B
private EventHandler<ActionEvent> EH;
public B() {
EH = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String value = ((Button) event.getSource()).getText();
if (value.equals("Przycisk")) {
System.out.println("Kliknales przycisk");
}
}
};
}