からシーンを開き、プログラム全体の複数のシーンがここに格納され、それは非常に読み困難になっています。JavaFXのは - 私はJavaFXのコードのすべてを保持している<em>Main.java</em>を持っている別のクラスのイベント
それぞれの「スクリーン」(Scene
)を別々の.javaクラスに保存して、もっと簡単に見つけたり変更したりできるようにしたいと思います。私はJavaFXを初めて使い、まだOOPを学んでいます。
以下のサンプルでは、Button
クリックイベントで新しいScene
(別の.javaクラスから)を開きたいとします。私は現在、これを単一のクラスで作業しています。しかし、これを別のファイルにどのように接近させるか分かりません。また、2つの配列リストを別のクラスに渡して、テーブルにデータを設定する必要があります。
以下は私が試したサンプルです。
Button
:
goToNextScene = new Button("View next scene");
goToNextScene.setOnAction(e -> window.setScene(AnotherClassA.sceneLayout, aList, bList));
// another try:
goToNextScene.setOnAction(e -> AnotherClassA.sceneLayout(aList, bList));
新しいクラス:事前に(渡された配列のリストを表示するための複数のボタンと、すぐに二つのテーブルを持つだけで画面)
public class AnotherClassA {
private BorderPane bP;
private HBox hBtnMenu;
private Button hMenuBtnA, hMenuBtnB, returnBtn;
public Scene sceneLayout;
public Scene sceneLayout(ArrayList aList, ArrayList bList) {
// array lists not used yet, but will come
hBtnMenu = new HBox();
hBtnMenu.setSpacing(10);
hBtnMenu.setPadding(new Insets(10,10,10,10));
hMenuBtnA = new Button("Btn A");
//hMenuBtnA.setOnAction(e -> window.setScene(AnotherClassA.sceneA));
hMenuBtnB = new Button("Btn B");
//hMenuBtnB.setOnAction(e -> window.setScene(AnotherClassB.sceneB));
returnBtn = new Button("Return to Home");
//returnBtn.setOnAction(e -> window.setScene(Main.splashScene));
hBtnMenu.getChildren().addAll(hMenuBtnA, hMenuBtnB, returnBtn);
bP = new BorderPane();
bP.setTop(hBtnMenu);
animalSceneLayout = new Scene(bP, 1200, 760);
return asceneLayout;
}
}
感謝。
をあなたは、公共 'のようなあなたのすべてのクラスでシーンを拡張することができますSceneAはSceneを拡張し、コンストラクタを作成します 'public SceneA(親ルート、ArrayList a、ArrayList b) \t { \t \tスーパー(ルート); \t} ' その後: ' goToNextScene.setOnAction(E - > window.setScene(新しいSceneA(新AnchorPane()、aListの、bList));お返事のための ' – DVarga
@DVargaのおかげで、これは私が「正確に何であります私の探している!:)完璧に動作します!私はいくつかのインターネットポイントをあなたの方法で送ることができます。答えとして投稿した場合:)再びありがとう – webstudent