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()
- SplashScreen
homeStage()
- 主屏幕
mainStage()
- LoginScreen
我该怎么办?