Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Program6;
- import javafx.animation.KeyFrame;
- import javafx.animation.Timeline;
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.Pane;
- import javafx.stage.Stage;
- import javafx.util.Duration;
- import javafx.animation.PathTransition;
- import javafx.scene.image.ImageView;
- import javafx.scene.layout.Pane;
- import javafx.scene.shape.Line;
- public class AirplaneLanding extends Application {
- @Override // Override the start method in the Application class
- public void start(Stage primaryStage) {
- // Create a pane
- Pane pane = new Pane();
- // Add an image view and add it to pane
- ImageView imageView = new ImageView("image/airplane.png");
- pane.getChildren().add(imageView);
- // Create a path transition
- PathTransition pt = new PathTransition(Duration.millis(5000),
- new Line(100, 100, 400, 400), imageView);
- pt.setOrientation(PathTransition.OrientationType.NONE);
- pt.setCycleCount(5);
- HBox hBox = new HBox();
- hBox.setSpacing(10);
- hBox
- .setAlignment(Pos.CENTER);
- Button btStart = new Button("Start");
- btStart.setOnAction(e-> pt.play()); // Start animation
- Button btStop = new Button("Start");
- btStop.setOnAction(e-> pt.stop()); // Start animation
- hBox.getChildren().add(btStart);
- hBox.getChildren().add(btStop);
- BorderPane borderPane = new BorderPane();
- borderPane.setCenter(pane);
- borderPane.setBottom(hBox);
- BorderPane.setAlignment(hBox, Pos.CENTER);
- // Create a scene and place it in the stage
- Scene scene = new Scene(pane, 600, 600);
- primaryStage.setTitle("Airplane Landing"); // Set the stage title
- primaryStage.setScene(scene); // Place the scene in the stage
- primaryStage.show(); // Display the stage
- }
- /**
- * The main method is only needed for the IDE with limited
- * JavaFX support. Not needed for running from the command line.
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement