Monty374

JFX 7.6

Dec 7th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. package fadetransitiondemo;
  2.  
  3. import javafx.animation.FadeTransition;
  4. import javafx.animation.Timeline;
  5. import javafx.application.Application;
  6. import javafx.scene.Scene;
  7. import javafx.scene.layout.Pane;
  8. import javafx.scene.paint.Color;
  9. import javafx.scene.shape.Ellipse;
  10. import javafx.stage.Stage;
  11. import javafx.util.Duration;
  12.  
  13. public class FadeTransitionDemo extends Application {
  14. @Override // Override the start method in the Application class
  15. public void start(Stage primaryStage) {
  16. // Place an ellipse to the pane
  17. Pane pane = new Pane();
  18. Ellipse ellipse = new Ellipse(10, 10, 100, 50);
  19. ellipse.setFill(Color.RED);
  20. ellipse.setStroke(Color.BLACK);
  21. ellipse.centerXProperty().bind(pane.widthProperty().divide(2));
  22. ellipse.centerYProperty().bind(pane.heightProperty().divide(2));
  23. ellipse.radiusXProperty().bind(
  24. pane.widthProperty().multiply(0.4));
  25. ellipse.radiusYProperty().bind(
  26. pane.heightProperty().multiply(0.4));
  27. pane.getChildren().add(ellipse);
  28.  
  29. // Apply a fade transition to ellipse
  30. FadeTransition ft =
  31. new FadeTransition(Duration.millis(3000), ellipse);
  32. ft.setFromValue(1.0);
  33. ft.setToValue(0.1);
  34. ft.setCycleCount(Timeline.INDEFINITE);
  35. ft.setAutoReverse(true);
  36. ft.play(); // Start animation
  37.  
  38. // Control animation
  39. ellipse.setOnMousePressed(e -> ft.pause());
  40. ellipse.setOnMouseReleased(e -> ft.play());
  41.  
  42. // Create a scene and place it in the stage
  43. Scene scene = new Scene(pane, 200, 150);
  44. primaryStage.setTitle("FadeTransitionDemo"); // Set the stage title
  45. primaryStage.setScene(scene); // Place the scene in the stage
  46. primaryStage.show(); // Display the stage
  47. }
  48.  
  49. /**
  50. * The main method is only needed for the IDE with limited
  51. * JavaFX support. Not needed for running from the command line.
  52. */
  53. public static void main(String[] args) {
  54. launch(args);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment