0
現在、ボタンをクリックしたときにウィンドウ(シーン)チェンジャーを作成しようとしています。具体的には、ユーザーにログインするときにウィンドウを変更します。どのようにして冗長コードを減らし、ウィンドウを集中管理するためのメソッドを配置するかを知りたい。それに続く特定のデザインパターンはありますか?FXFを使用しているJavaFXウィンドウチェンジャー
Main.java
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = (Parent) FXMLLoader.load(getClass().getResource("Login.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("Styles.css");
stage.setScene(scene);
stage.setTitle("App");
stage.setResizable(false);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
LoginController.java
public class LoginController implements Initializable {
@FXML
private TextField email;
@FXML
private PasswordField password;
@FXML
private Button buttonLogin;
private Stage stage;
@Override
public void initialize(URL url, ResourceBundle rb) {}
@FXML
private void login(ActionEvent event) throws Exception {
stage = (Stage) buttonLogin.getScene().getWindow();
Parent root = (Parent) FXMLLoader.load(getClass().getResource("Profile.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("Styles.css");
stage.setScene(scene);
stage.centerOnScreen();
stage.show();
}
}
ありがとう:
はこれまでのところ、私はこれを持っています!
'public static void loadSceneToStage(String resourceName、Stage stage)throws IOException {...}' ??? – fabian