N
N
Neonoviiwolf2017-12-25 02:17:21
JavaFX
Neonoviiwolf, 2017-12-25 02:17:21

How to transfer data from one class connected to fxml to another connected fxml?

Kind
Here I asked how to split the controls into parts How to split the code in javafx into several controls?
Now the question arose, how can I transfer data from one control to another. those.

public class Main extends Application implements Initializable

and
public class RadioButtons implements Initializable {

something is being done in Main and I need to pass data to RadioButtons, but how?
clarifications:
I have a lot of different controls, and therefore I decided to separate them and just put them in sample.fxml
<fx:include source="radio_button.fxml" fx:id="radioButtonLayout"></fx:include>

in the fxml "radio_button" itself, I wrote
<AnchorPane xmlns="http://javafx.com/javafx"
            id="radio_buttons_pane"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="controller.RadioButtons"
            prefHeight="400.0" prefWidth="600.0">
.....
</AnchorPane>

created a class
public class RadioButtons implements Initializable {

    public RadioButtons() {
    }
 @FXML
    RadioButton radio1, radio2;
.....
}

in sample.fxml there was Button "addDB", when it is pressed, I have to write to the database if all fields are filled.
I am now also feeling RxJava and I want all this to happen through it, although it does not affect the answer, because now you just need to pass the link of the subscriber
public class Main extends Application implements Initializable {
    @FXML
    Button  addProduct;
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        Observable<String> observable;
        observable = Observable.just("test");

        addProduct.setOnAction(event -> {
            new RadioButtons().addDB(observable); //тут я не могу писать new, т.к. класс уже существует, при старте программы

        });
}

public class RadioButtons implements Initializable {
    public void addDB(Observable observable) {
        Observer<String> server = new Observer<String>() {
            @Override
            public void onSubscribe(Disposable disposable) {

            }

            @Override
            public void onNext(String s) {
                System.out.print(s);
                eventBus();

            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onComplete() {

            }
        };
        observable.subscribe(server);
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Neonoviiwolf, 2017-12-26
@Neonoviiwolf

I don't see a solution for my case, I need to get a class reference
public class RadioButtons implements Initializable

A
Alexander Korobov, 2017-12-26
@superbadlam

get a link to the nested controller and use this link in the button handler of the button.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question