Animation 在JavaFx中淡入/淡出屏幕

Animation 在JavaFx中淡入/淡出屏幕,animation,javafx,screen,fadein,fadeout,Animation,Javafx,Screen,Fadein,Fadeout,我制作了一个具有主屏幕的JavaFx应用程序。主屏幕包含按钮,每个按钮显示不同的屏幕。现在,当我按下一个按钮时,我想将当前屏幕设置为“淡出”,将新屏幕设置为“淡出” public class GuiPractice extends Application { private Stage stage; public static void main(String[] args) { Application.launch(GuiPractice.class, (j

我制作了一个具有主屏幕的JavaFx应用程序。主屏幕包含按钮,每个按钮显示不同的屏幕。现在,当我按下一个按钮时,我想将当前屏幕设置为“淡出”,将新屏幕设置为“淡出”

public class GuiPractice extends Application {

    private Stage stage;

    public static void main(String[] args) {
        Application.launch(GuiPractice.class, (java.lang.String[])null);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        try{
            stage = primaryStage;
            stage.setTitle("HOME SCREEN");
            gotoWelcome();
            stage.show();            
        } catch(Exception ex){
            Logger.getLogger(GuiPractice.class.getName()).log(Level.SEVERE,null,ex);
        }
    }


    private void gotoWelcome(){
        try{
            WelcomePageController wc = (WelcomePageController)     replaceScene("WelcomePage.fxml");  // Check 'replaceScene' Below
            wc.setApp(this);
        } catch (Exception ex){
            Logger.getLogger(GuiPractice.class.getName()).log(Level.SEVERE,null,ex);
        }
    }
    // When I Press Button Action Handler Calls This Method..
    // This Method is Working Fine, Except For the FandIn Portion
    private void gotoSignin(){
        try{

            SigninPageController wc = (SigninPageController)     replaceScene("SigninPage.fxml"); // Check 'replaceScene' Below
            wc.setApp(this);           

            /// THIS PORTION IS FADE TRANSITION, IT IS NOT WORKING
            FadeTransition ft = new FadeTransition(Duration.millis(3000));
            ft.setFromValue(0.0);
            ft.setToValue(1.0);

            ft.play();


        } catch (Exception ex){
            Logger.getLogger(GuiPractice.class.getName()).log(Level.SEVERE,null,ex);
        }
    }

    private Initializable replaceScene(String fxml) throws Exception {
        FXMLLoader loader = new FXMLLoader();
        InputStream ins = GuiPractice.class.getResourceAsStream(fxml);
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        loader.setLocation(GuiPractice.class.getResource(fxml));
        AnchorPane page;
        try {
            page = (AnchorPane) loader.load(ins);
        } finally {
            ins.close();
        }
        Scene scene = new Scene(page);
        stage.setScene(scene);
        stage.sizeToScene();
        return (Initializable) loader.getController();
    }

}

您需要将要应用
转换的
节点
传递给
FadeTransition
的构造函数

方法1

因此,您可以在
scene=new scene(第页)

不过,欢迎屏幕上也会出现
淡入淡出效果
,您必须应用一些逻辑来避免它

方法2

fxml
装入
gotoSignin()
/获取
Anchorpane
参考并将其传递给控制器。不过,我相信这将为您当前的设计带来很多变化!你可以打个电话决定


希望有帮助

是的,当然,你可以有一个淡出效果-只是倒数你的淡出转换的值,比如:

FadeTransition ft = new FadeTransition(Duration.millis(3000), page);
ft.setFromValue(1);
ft.setToValue(0);
ft.play();
酷:):)第一种方法在我的代码上运行良好。。非常感谢你@ltachiUchiha。。但是现在我在想,当屏幕消失时,我是否可以应用淡出转换。。再一次谢谢你
FadeTransition ft = new FadeTransition(Duration.millis(3000), page);
ft.setFromValue(1);
ft.setToValue(0);
ft.play();