Advertisement
Guest User

MyHelloToTheWorldController.java

a guest
Oct 15th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.23 KB | None | 0 0
  1. import java.net.URL;
  2. import java.util.ResourceBundle;
  3.  
  4. import javafx.animation.KeyFrame;
  5. import javafx.animation.KeyValue;
  6. import javafx.animation.ParallelTransition;
  7. import javafx.animation.RotateTransition;
  8. import javafx.animation.ScaleTransition;
  9. import javafx.animation.SequentialTransition;
  10. import javafx.animation.Timeline;
  11. import javafx.animation.TranslateTransition;
  12. import javafx.event.ActionEvent;
  13. import javafx.fxml.FXML;
  14. import javafx.scene.control.Button;
  15. import javafx.scene.input.MouseEvent;
  16. import javafx.scene.layout.AnchorPane;
  17. import javafx.scene.shape.Arc;
  18. import javafx.util.Duration;
  19.  
  20. public class MyHelloToTheWorldController {
  21.  
  22.     @FXML
  23.     private ResourceBundle resources;
  24.  
  25.     @FXML
  26.     private URL location;
  27.  
  28.     @FXML
  29.     private AnchorPane anchorPane;
  30.  
  31.     @FXML
  32.     private Button alignButton;
  33.  
  34.     @FXML
  35.     private Button fixButton;
  36.  
  37.     @FXML
  38.     private Arc yellowman;
  39.  
  40.     @FXML
  41.     void alignButtonClicked(ActionEvent event) {
  42.        
  43.         if (alignButton.getRotate() != 360) {
  44.             TranslateTransition translateTransition = new TranslateTransition(
  45.                     Duration.millis(1000), alignButton);
  46.             translateTransition.setToX(50);
  47.             translateTransition.setCycleCount(2);
  48.             translateTransition.setAutoReverse(true);
  49.  
  50.             RotateTransition rotateTransition = new RotateTransition(
  51.                     Duration.millis(2000), alignButton);
  52.             rotateTransition.setByAngle(14f);
  53.             rotateTransition.setCycleCount(1);
  54.  
  55.             ScaleTransition scaleTransition = new ScaleTransition(
  56.                     Duration.millis(1000), alignButton);
  57.             scaleTransition.setToX(2f);
  58.             scaleTransition.setToY(4f);
  59.             scaleTransition.setCycleCount(2);
  60.             scaleTransition.setAutoReverse(true);
  61.  
  62.             ParallelTransition parallelTransition = new ParallelTransition();
  63.             parallelTransition.getChildren().addAll(translateTransition,
  64.                     rotateTransition, scaleTransition);
  65.             parallelTransition.play();
  66.         } else {
  67.             TranslateTransition translateTransition = new TranslateTransition(
  68.                     Duration.millis(100), alignButton);
  69.             translateTransition.setToX(alignButton.getTranslateX() - 6);
  70.             translateTransition.setCycleCount(6);
  71.             translateTransition.setAutoReverse(true);
  72.             translateTransition.play();
  73.         }
  74.     }
  75.  
  76.     @FXML
  77.     void fixButtonClicked(ActionEvent event) {
  78.        
  79.         if (anchorPane.getRotate() != 360) {
  80.             RotateTransition rotateTransition = new RotateTransition(
  81.                     Duration.millis(2300), anchorPane);
  82.             rotateTransition.setByAngle(-8f);
  83.             rotateTransition.setCycleCount(1);
  84.  
  85.             RotateTransition rotateTransition2 = new RotateTransition(
  86.                     Duration.millis(1100), anchorPane);
  87.             rotateTransition2.setByAngle(4f);
  88.             rotateTransition2.setCycleCount(1);
  89.  
  90.             RotateTransition rotateTransition3 = new RotateTransition(
  91.                     Duration.millis(1200), anchorPane);
  92.             rotateTransition3.setByAngle(-1f);
  93.             rotateTransition3.setCycleCount(1);
  94.  
  95.             SequentialTransition sequentialTransition = new SequentialTransition();
  96.             sequentialTransition.getChildren().addAll(rotateTransition,
  97.                     rotateTransition2, rotateTransition3);
  98.             sequentialTransition.setCycleCount(1);
  99.             sequentialTransition.setAutoReverse(true);
  100.  
  101.             sequentialTransition.play();
  102.             fixButton.setDisable(true);
  103.         }
  104.     }
  105.  
  106.     @FXML
  107.     void enteredYellowMan(MouseEvent event) {
  108.         System.out.println("enter yello");
  109.         if (yellowman.getStartAngle() == 50d) {
  110.             final Timeline timeline = new Timeline();
  111.             timeline.setCycleCount(4);
  112.             timeline.setAutoReverse(true);
  113.  
  114.             final KeyValue kv1 = new KeyValue(yellowman.startAngleProperty(),
  115.                     50);
  116.             final KeyValue kv2 = new KeyValue(yellowman.lengthProperty(), 270);
  117.             final KeyFrame kf = new KeyFrame(Duration.ZERO, kv1, kv2);
  118.  
  119.             final KeyValue kv3 = new KeyValue(yellowman.startAngleProperty(), 0);
  120.             final KeyValue kv4 = new KeyValue(yellowman.lengthProperty(), 360);
  121.             final KeyFrame kf2 = new KeyFrame(Duration.millis(500), kv3, kv4);
  122.  
  123.             timeline.getKeyFrames().addAll(kf, kf2);
  124.             timeline.play();
  125.         }
  126.     }
  127.  
  128.     @FXML
  129.     void clickedYellowMan(MouseEvent event) {
  130.         System.out.println("click yello");
  131.         final Timeline timeline = new Timeline();
  132.         timeline.setCycleCount(Timeline.INDEFINITE);
  133.         timeline.setAutoReverse(true);
  134.  
  135.         final KeyValue kv = new KeyValue(yellowman.startAngleProperty(), 0);
  136.         final KeyValue kv2 = new KeyValue(yellowman.lengthProperty(), 360);
  137.         final KeyFrame kf = new KeyFrame(Duration.millis(200), kv, kv2);
  138.  
  139.         timeline.getKeyFrames().add(kf);
  140.  
  141.         TranslateTransition translateTransition = new TranslateTransition(
  142.                 Duration.millis(4000), yellowman);
  143.         translateTransition.setToX(yellowman.getTranslateX() + 2000);
  144.         translateTransition.setCycleCount(1);
  145.         translateTransition.play();
  146.  
  147.         ParallelTransition parallelTransition = new ParallelTransition();
  148.         parallelTransition.getChildren().addAll(timeline, translateTransition);
  149.         parallelTransition.play();
  150.     }
  151.  
  152.     @FXML
  153.     void initialize() {
  154.         assert alignButton != null : "fx:id=\"alignButton\" was not injected: check your FXML file 'FirstGui.fxml'.";
  155.         assert anchorPane != null : "fx:id=\"anchorPane\" was not injected: check your FXML file 'FirstGui.fxml'.";
  156.         assert fixButton != null : "fx:id=\"fixButton\" was not injected: check your FXML file 'FirstGui.fxml'.";
  157.         assert yellowman != null : "fx:id=\"yellowman\" was not injected: check your FXML file 'FirstGui.fxml'.";
  158.     }
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement