Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. package Program6;
  2.  
  3. import javafx.animation.KeyFrame;
  4. import javafx.animation.Timeline;
  5. import javafx.application.Application;
  6. import javafx.geometry.Insets;
  7. import javafx.geometry.Pos;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.layout.BorderPane;
  11. import javafx.scene.layout.HBox;
  12. import javafx.scene.layout.Pane;
  13. import javafx.stage.Stage;
  14. import javafx.util.Duration;
  15. import javafx.animation.PathTransition;
  16. import javafx.scene.image.ImageView;
  17. import javafx.scene.layout.Pane;
  18. import javafx.scene.shape.Line;
  19.  
  20. public class AirplaneLanding extends Application {
  21.     @Override // Override the start method in the Application class
  22.     public void start(Stage primaryStage) {
  23.         // Create a pane
  24.         Pane pane = new Pane();
  25.  
  26.         // Add an image view and add it to pane
  27.         ImageView imageView = new ImageView("image/airplane.png");
  28.         pane.getChildren().add(imageView);
  29.  
  30.         // Create a path transition
  31.         PathTransition pt = new PathTransition(Duration.millis(5000),
  32.                 new Line(100, 100, 400, 400), imageView);
  33.         pt.setOrientation(PathTransition.OrientationType.NONE);
  34.         pt.setCycleCount(5);
  35.  
  36.  
  37.         HBox hBox = new HBox();
  38.         hBox.setSpacing(10);
  39.         hBox
  40.                 .setAlignment(Pos.CENTER);
  41.         Button btStart = new Button("Start");
  42.         btStart.setOnAction(e-> pt.play()); // Start animation
  43.         Button btStop = new Button("Start");
  44.         btStop.setOnAction(e-> pt.stop()); // Start animation
  45.         hBox.getChildren().add(btStart);
  46.         hBox.getChildren().add(btStop);
  47.  
  48.         BorderPane borderPane = new BorderPane();
  49.         borderPane.setCenter(pane);
  50.         borderPane.setBottom(hBox);
  51.         BorderPane.setAlignment(hBox, Pos.CENTER);
  52.  
  53.  
  54.  
  55.         // Create a scene and place it in the stage
  56.         Scene scene = new Scene(pane, 600, 600);
  57.         primaryStage.setTitle("Airplane Landing"); // Set the stage title
  58.         primaryStage.setScene(scene); // Place the scene in the stage
  59.         primaryStage.show(); // Display the stage
  60.     }
  61.  
  62.     /**
  63.      * The main method is only needed for the IDE with limited
  64.      * JavaFX support. Not needed for running from the command line.
  65.      */
  66.     public static void main(String[] args) {
  67.         launch(args);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement