Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.URL;
- import java.util.ResourceBundle;
- import javafx.animation.KeyFrame;
- import javafx.animation.KeyValue;
- import javafx.animation.ParallelTransition;
- import javafx.animation.RotateTransition;
- import javafx.animation.ScaleTransition;
- import javafx.animation.SequentialTransition;
- import javafx.animation.Timeline;
- import javafx.animation.TranslateTransition;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.scene.control.Button;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.AnchorPane;
- import javafx.scene.shape.Arc;
- import javafx.util.Duration;
- public class MyHelloToTheWorldController {
- @FXML
- private ResourceBundle resources;
- @FXML
- private URL location;
- @FXML
- private AnchorPane anchorPane;
- @FXML
- private Button alignButton;
- @FXML
- private Button fixButton;
- @FXML
- private Arc yellowman;
- @FXML
- void alignButtonClicked(ActionEvent event) {
- if (alignButton.getRotate() != 360) {
- TranslateTransition translateTransition = new TranslateTransition(
- Duration.millis(1000), alignButton);
- translateTransition.setToX(50);
- translateTransition.setCycleCount(2);
- translateTransition.setAutoReverse(true);
- RotateTransition rotateTransition = new RotateTransition(
- Duration.millis(2000), alignButton);
- rotateTransition.setByAngle(14f);
- rotateTransition.setCycleCount(1);
- ScaleTransition scaleTransition = new ScaleTransition(
- Duration.millis(1000), alignButton);
- scaleTransition.setToX(2f);
- scaleTransition.setToY(4f);
- scaleTransition.setCycleCount(2);
- scaleTransition.setAutoReverse(true);
- ParallelTransition parallelTransition = new ParallelTransition();
- parallelTransition.getChildren().addAll(translateTransition,
- rotateTransition, scaleTransition);
- parallelTransition.play();
- } else {
- TranslateTransition translateTransition = new TranslateTransition(
- Duration.millis(100), alignButton);
- translateTransition.setToX(alignButton.getTranslateX() - 6);
- translateTransition.setCycleCount(6);
- translateTransition.setAutoReverse(true);
- translateTransition.play();
- }
- }
- @FXML
- void fixButtonClicked(ActionEvent event) {
- if (anchorPane.getRotate() != 360) {
- RotateTransition rotateTransition = new RotateTransition(
- Duration.millis(2300), anchorPane);
- rotateTransition.setByAngle(-8f);
- rotateTransition.setCycleCount(1);
- RotateTransition rotateTransition2 = new RotateTransition(
- Duration.millis(1100), anchorPane);
- rotateTransition2.setByAngle(4f);
- rotateTransition2.setCycleCount(1);
- RotateTransition rotateTransition3 = new RotateTransition(
- Duration.millis(1200), anchorPane);
- rotateTransition3.setByAngle(-1f);
- rotateTransition3.setCycleCount(1);
- SequentialTransition sequentialTransition = new SequentialTransition();
- sequentialTransition.getChildren().addAll(rotateTransition,
- rotateTransition2, rotateTransition3);
- sequentialTransition.setCycleCount(1);
- sequentialTransition.setAutoReverse(true);
- sequentialTransition.play();
- fixButton.setDisable(true);
- }
- }
- @FXML
- void enteredYellowMan(MouseEvent event) {
- System.out.println("enter yello");
- if (yellowman.getStartAngle() == 50d) {
- final Timeline timeline = new Timeline();
- timeline.setCycleCount(4);
- timeline.setAutoReverse(true);
- final KeyValue kv1 = new KeyValue(yellowman.startAngleProperty(),
- 50);
- final KeyValue kv2 = new KeyValue(yellowman.lengthProperty(), 270);
- final KeyFrame kf = new KeyFrame(Duration.ZERO, kv1, kv2);
- final KeyValue kv3 = new KeyValue(yellowman.startAngleProperty(), 0);
- final KeyValue kv4 = new KeyValue(yellowman.lengthProperty(), 360);
- final KeyFrame kf2 = new KeyFrame(Duration.millis(500), kv3, kv4);
- timeline.getKeyFrames().addAll(kf, kf2);
- timeline.play();
- }
- }
- @FXML
- void clickedYellowMan(MouseEvent event) {
- System.out.println("click yello");
- final Timeline timeline = new Timeline();
- timeline.setCycleCount(Timeline.INDEFINITE);
- timeline.setAutoReverse(true);
- final KeyValue kv = new KeyValue(yellowman.startAngleProperty(), 0);
- final KeyValue kv2 = new KeyValue(yellowman.lengthProperty(), 360);
- final KeyFrame kf = new KeyFrame(Duration.millis(200), kv, kv2);
- timeline.getKeyFrames().add(kf);
- TranslateTransition translateTransition = new TranslateTransition(
- Duration.millis(4000), yellowman);
- translateTransition.setToX(yellowman.getTranslateX() + 2000);
- translateTransition.setCycleCount(1);
- translateTransition.play();
- ParallelTransition parallelTransition = new ParallelTransition();
- parallelTransition.getChildren().addAll(timeline, translateTransition);
- parallelTransition.play();
- }
- @FXML
- void initialize() {
- assert alignButton != null : "fx:id=\"alignButton\" was not injected: check your FXML file 'FirstGui.fxml'.";
- assert anchorPane != null : "fx:id=\"anchorPane\" was not injected: check your FXML file 'FirstGui.fxml'.";
- assert fixButton != null : "fx:id=\"fixButton\" was not injected: check your FXML file 'FirstGui.fxml'.";
- assert yellowman != null : "fx:id=\"yellowman\" was not injected: check your FXML file 'FirstGui.fxml'.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement