0

私はjavafxにかなり慣れていません。画面を切り替える方法はたくさんありましたが、どうにかうまくいかず、このロジックを使用することを考えました。プロジェクトをやりすぎる前に、それを続けることができるかどうかを知る必要があります.

 @FXML
public void nextAfterPassangerButtonClicked() throws Exception {

    MainScreenDatabaseHandler a = new MainScreenDatabaseHandler(getId(), getFirstName(), getLastName(), getOtherName(), getSexSelection(), getMobileNumber(), getEmergencyContact(), getHomeAdress());
    //send collected data to database
    passangerPaymentAnchorPane.getChildren().remove(0);
    Node node = FXMLLoader.load(getClass().getResource("CargoPayment.fxml"));
    passangerPaymentAnchorPane.getChildren().add(node);
}

//Handle All Menu Bar Buttons
@FXML
public void startPageBarButtonClicked() throws Exception {
    passangerPaymentAnchorPane.getChildren().remove(0);
    mainAnchor.getChildren().remove(0);
    Node node = FXMLLoader.load(getClass().getResource("MainScreen.fxml"));
    mainAnchor.getChildren().add(node);
}

public void allPassangersMenuBarButtonClicked() throws Exception {

    passangerPaymentAnchorPane.getChildren().remove(0);
    Node node = FXMLLoader.load(getClass().getResource("AllPassangersView.fxml"));
    passangerPaymentAnchorPane.getChildren().add(node);
}

ボタンの 1 つをクリックすると、現在のシーンが削除され、関連する fxml が読み込まれます。ありがとうございました。passangerPaymentAnchorPane は、他の fxml がロードおよびアンロードされるマザー ペインのように機能します。

4

2 に答える 2

1

主なアプローチに問題はありません。つまり、fxml ファイルをロードするためのコンテナのように機能するレイアウトがあります。その子は、何らかのイベント アクションで置き換えられます。loadView(String fxmlFile)上記の繰り返しの「layout.remove - fxmlloader.load() - layout.add()」のペアがリファクタリングされるメソッドのように、プロジェクトが成長する前にコードをリファクタリングすることをお勧めします。さらに、fxml ファイルの解析と読み込みはコストのかかる作業であるため、次のように遅延してビューのみを更新します。

Pane cargoPaymentPane;
CargoPaymentController cargoPaymentController;
FXMLLoader fxmlLoader = new FXMLLoader();

public void loadCargoPaymentView(String newCargoData) {
    if(cargoPaymentPane == null) { 
        cargoPaymentPane = fxmlLoader.load(getClass().getResource("CargoPayment.fxml").openStream());
        cargoPaymentController = (CargoPaymentController) fxmlLoader.getController();
    }
    cargoPaymentController.updateView(newCargoData);
}
于 2013-07-17T12:46:16.687 に答える
1

javaFx マルチスクリーンの問題にも苦労しました。最終的に以下のように解決しました。githubにコードを追加しました

https://github.com/nrkkalyan/javafx

コメントや提案をお気軽に。

于 2014-01-23T00:21:59.963 に答える