Hello. There is a method for creating a new form and a stream, after which I would like to create this form.
Method:
public void showGameForm() { try { System.out.println("1"); FXMLLoader gameLoader = new FXMLLoader(getClass().getResource("view/game/GameForm.fxml")); System.out.println("2"); SplitPane gameForm = (SplitPane) gameLoader.load(); // Создаём диалоговое окно Stage. System.out.println("3"); Stage gameStage = new Stage(); System.out.println("4"); gameStage.setTitle("HumanGo"); //gameStage.initModality(Modality.WINDOW_MODAL); System.out.println("5"); gameStage.initModality(Modality.APPLICATION_MODAL); gameStage.initOwner(primaryStage); System.out.println("6"); Scene scene = new Scene(gameForm); System.out.println("7"); gameStage.setScene(scene); // Отображаем диалоговое окно и ждём, пока пользователь его не закроет //gameStage.showAndWait(); System.out.println("8"); gameStage.show(); System.out.println("gameStage:" + gameStage.toString()); System.out.println("loader:" + gameLoader.toString()); System.out.println("scene:" + scene.toString()); } catch (IOException e) { e.printStackTrace(); } The stream on which the new frame should open ( mainApp.showGameForm(); ):
public Task taskObject = new Task<String>() { @Override public String call() { while (true) { if (isCancelled()) { updateMessage("Cancelled"); break; } progressIndicator.setOpacity(indicatorOpacity); requestUserSession.setUserSession(parameters,null); responseUserSession = ObjectRequestSender.sendGetRequest(LOG_URL, requestUserSession); System.out.println("Имя пользователя: "+responseUserSession.getUserName()+"\tId пользователя: "+responseUserSession.getUserId(responseUserSession.getUserName())); updateMessage("Имя пользователя: "+responseUserSession.getUserName()+"\tId пользователя: "+responseUserSession.getUserId(responseUserSession.getUserName())); if (responseUserSession.getAuth() == "AUTH") { if (indicatorOpacity >= 0) { indicatorOpacity -= 0.35; } else { indicatorOpacity = 0; cancel(); mainApp.showGameForm(); } } try { Thread.sleep(250); } catch (InterruptedException interrupted) { if (isCancelled()) { updateMessage("Cancelled"); break; } } } return parameters; } }; The program hangs on the showGameForm () method string. Stage gameStage = new Stage(); If I call the showGameForm () method from any place other than the stream, then everything works fine. All other thread commands work fine. Tell me, please, can someone tell me what my mistake is. Thought that the error might be that taskObject is of type String. Tried to make it Void - did not help. As I understand it, the stream running on the current frame somehow prevents the creation of a new scene. I understand that the decision is not ideal, I am ready to listen to any criticism or advice.
FXstream (Platform.runLater()). It may be worthwhile to take a listener to the status of the thread and call inside it. If necessary, I can write in more detail tomorrow. - Andrey M