2017-06-04 11 views
0

このコードではどうなりますか? 私はかなり混乱しています! 私はメインステージで自分のシーンを変えたいと思っていました。javafxのシーンを変更する

public class SignInController { 
    @FXML 
    TextField SignInPassword; 

    @FXML 
    TextField SignInUsername; 

    @FXML 
    CheckBox RememberMe; 

    public void signUpScene(MouseEvent mouseEvent) throws IOException { 
     Timeline timeline = new Timeline(); 
     Scene SignUpScene = new Scene(FXMLLoader.load(getClass().getResource("sign up.fxml")),700,700); 
     Main.pstage.setScene(SignUpScene); 
     timeline.getKeyFrames().addAll(
       new KeyFrame(Duration.ZERO,new KeyValue(SignUpScene.getWidth(),0.0)), 
       new KeyFrame(Duration.millis(1000.0d),new KeyValue(SignUpScene.getWidth(),700.0)) 
     ); 

     timeline.play(); 
    } 
} 
+0

これもコンパイルされません。 –

+0

@James_D知っていますが、どうしたらいいですか? – Mohammasd

+0

2つのダブルを指定する 'KeyValue'を作成することはできません。あなたにそれを伝えるコンパイルエラーはありませんか?あなたは 'WritableValue'(通常は' Property')が必要です。実際に何をしようとしていますか? –

答えて

3

あなたの新しいシーンを保持するステージの幅をアニメーション化したい場合は、使用することができTransition

public void signUpScene(MouseEvent mouseEvent) throws IOException { 
     Scene SignUpScene = new Scene(FXMLLoader.load(getClass().getResource("sign up.fxml")),700,700); 
     Main.pstage.setScene(SignUpScene); 

     Rectangle clip = new Rectangle(0, 700); 

     Transition animateStage = new Transition() { 
      { 
       setCycleDuration(Duration.millis(1000)); 
      } 
      @Override 
      protected void interpolate(double t) { 
       Main.pstage.setWidth(t * 700.0); 
      } 
     }; 
     animateStage.play(); 
    } 
} 

たぶん、より良いアプローチは、徐々にクリップを使用して新しいシーンを明らかにすることだろう:

public void signUpScene(MouseEvent mouseEvent) throws IOException { 

     Parent root = FXMLLoader.load(getClass().getResource("sign up.fxml")); 

     Scene SignUpScene = new Scene(root,700,700); 
     Main.pstage.setScene(SignUpScene); 

     Rectangle clip = new Rectangle(0, 700); 
     Timeline animate = new Timeline(
      new KeyFrame(Duration.millis(1000), 
       new KeyValue(clip.widthProperty(), 700.0)); 
     root.setClip(clip); 
     // when animation finishes, remove clip: 
     animate.setOnFinished(e -> root.setClip(null)); 
     animate.play(); 
    } 
} 
+0

ありがとう – Mohammasd

関連する問題