import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
public static Stage mainStage;
private static Stage homeStage;
@Override
public void start(final Stage primaryStage) {
Application.setUserAgentStylesheet(STYLESHEET_CASPIAN);
splashStage(primaryStage);
primaryStage.show();
//mainStage();
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
// TODO Auto-generated method stub
for (int i = 1; i < 100; i++) {
try {
System.out.println(i);
if(i==99)
{
primaryStage.hide();
mainStage();
break;
}
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
};
new Thread(task).start();
}
public static void main(String[] args) {
launch(args);
}
public void mainStage()
{
try {
mainStage = new Stage(StageStyle.DECORATED);
FlowPane root = (FlowPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
mainStage.setScene(scene);
mainStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void homeStage()
{
try {
homeStage = new Stage(StageStyle.DECORATED);
Parent root = FXMLLoader.load(Main.class.getResource("Home.fxml"));
Scene scene = new Scene(root);
homeStage.setResizable(false);
homeStage.setScene(scene);
homeStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public void splashStage(Stage primaryStage)
{
try {
primaryStage.initStyle(StageStyle.TRANSPARENT);
FlowPane root = (FlowPane)FXMLLoader.load(getClass().getResource("Splash.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
} catch(Exception e) {
e.printStackTrace();
}
}
}
i
達到99之後,它不會打開mainStage
和primaryStage
沒有牆根爲什麼舞臺不開放?
功能的詳細信息如下。
splashStage()
- 閃屏
homeStage()
- 主屏幕
mainStage()
- LoginScreen
我應該怎麼辦?
您是否嘗試過使用Platform.runLater(() - > primaryStage ......),因爲您必須在JavaFX應用程序線程上做這樣的事情,舞臺提及的文檔 – Inge
是的,我試過但沒有工作。你有什麼想法從閃屏重定向主屏幕? –
@Keval:再試一次。我測試過它,它的工作原理:'Platform.runLater(() - > { primaryStage.hide(); mainStage(); });'如果它不工作,你沒有提供所需的信息重現問題。 (如果拋出異常,則包含堆棧跟蹤的異常將尤其重要) – fabian