我有Principal类,负责处理Stages的执行,并且在方法中,showAuto()称为InitialicePage(),用于Ventana Auto的加载
public class Principal extends Application {
private ArrayList<Stage> listaScene = new ArrayList<>();
private static Principal principal;
public static Principal getPrincipal() {
if (principal == null) {
principal = new Principal();
}
return principal;
}
public void createScene() throws IOException, Exception {
//metodo para cada ventana la controladora
Stage primaryStageAutomatico = ControllerAutoExp.initialicePage();
Principal.getPrincipal().getListScene().add(primaryStageAutomatico);
}
@Override
public void start(Stage primaryStage) throws Exception {
System.setProperty("glass.accessible.force", "false");
try {
createScene();
ControllerManejarDatos.initialicePage();
} catch (IOException ex) {
Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
ErrorLogger.recordError(ex);
}
}
public void showAuto(ActionEvent event) {
try {
boolean find = false;
int i = 0;
while (find == false && i < listaScene.size()) {
if (listaScene.get(i).getTitle().equals("Ventana Auto")) {
if (!listaScene.get(i).isShowing()) {
Stage primaryStageLista = ControllerAutoExp.initialicePage();
listaScene.add(i, primaryStageLista);
listaScene.get(i).initModality(Modality.APPLICATION_MODAL);
listaScene.get(i).show();
} else {
listaScene.get(i).close();
listaScene.get(i).initModality(Modality.APPLICATION_MODAL);
listaScene.get(i).show();
}
find = true;
} else {
i++;
}
}
} catch (Exception e) {
try {
ErrorLogger.recordError(e);
} catch (IOException ex) {
Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
如何从另一个班级获得正在运行的舞台?我想在ControllerAutoExp类中运行时在舞台上加载新的fxml。谢谢你的帮助
答案 0 :(得分:0)
将阶段定义移动到Principal
类的内部和任何方法的外部,并在其前面添加static
。然后,您可以使用Principal.primaryStage
来调用它。