简体   繁体   中英

How do I remove a scene in a stage in javafx?

I want to write a game that includes these classes:

--Game extends Application(pass its stage to below classes)
--StartUp extends Application(has stackpane that added to scene and scene added to stage)
--Menu extends Application
--GamePly extends Application

I want all of these classes use on stage. First of all, I start startUp class and after a few seconds I want to remove startUp stackpane and change the scene (for example read from an fxml file) but I'm a noob in javafx. Any ideas?

I believe THIS is what you are looking for. A member here posted this code awhile ago. If you want to change the entire scene, add another class that holds a static stage and set it in your main. You can use that to stage.setScene(Menu).

To remove the scene, you could create the scene directly in the stage.setScene(new Scene())

When you set a new scene, the old one will lose it's reference and the garbage collector will take care of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM