11package com .genuinecoder .javafxcircularscenetransition .scene1 ;
22
33import com .genuinecoder .javafxcircularscenetransition .HelloApplication ;
4+ import javafx .animation .Interpolator ;
5+ import javafx .animation .KeyFrame ;
6+ import javafx .animation .KeyValue ;
7+ import javafx .animation .Timeline ;
48import javafx .event .ActionEvent ;
59import javafx .fxml .FXML ;
610import javafx .fxml .FXMLLoader ;
11+ import javafx .scene .layout .Pane ;
712import javafx .scene .layout .StackPane ;
813import javafx .scene .layout .VBox ;
14+ import javafx .scene .shape .Circle ;
15+ import javafx .util .Duration ;
916
1017public class Scene1Controller {
1118
@@ -17,7 +24,28 @@ public class Scene1Controller {
1724 public void loadScene2 (ActionEvent actionEvent ) {
1825 try {
1926 FXMLLoader fxmlLoader = new FXMLLoader (HelloApplication .class .getResource ("scene2/scene2.fxml" ));
20- rootContainer .getScene ().setRoot (fxmlLoader .load ());
27+ Pane pane = fxmlLoader .load ();
28+ rootContainer .getChildren ().add (pane );
29+
30+ Circle circle = new Circle (50 );
31+ pane .setShape (circle );
32+ circle .radiusProperty ().addListener ((observable , oldValue , newValue ) -> {
33+ double size = newValue .doubleValue () * 2 ;
34+ pane .setMinSize (size , size );
35+ pane .setPrefSize (size , size );
36+ pane .setMaxSize (size , size );
37+ });
38+
39+ Timeline timeline = new Timeline ();
40+ KeyValue keyValue = new KeyValue (circle .radiusProperty (), 400 , Interpolator .EASE_OUT );
41+ KeyFrame keyFrame = new KeyFrame (Duration .seconds (0.5 ), keyValue );
42+ timeline .getKeyFrames ().add (keyFrame );
43+ timeline .play ();
44+ timeline .setOnFinished (event -> {
45+ rootContainer .getChildren ().remove (contentContainer );
46+ pane .setShape (null );
47+ });
48+
2149 } catch (Exception exp ) {
2250 exp .printStackTrace ();
2351 }
0 commit comments