iT邦幫忙

0

利用pathtransition做一個上下移動的文字 JAVAFX 求解

利用pathtransition做一個上下移動的文字,文字為javaFx,並且截圖結果跟code

package javafxapplication1;

import javafx.animation.PathTransition;

import javafx.animation.Timeline;

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Rectangle;

import javafx.scene.shape.Circle;

import javafx.stage.Stage;

import javafx.util.Duration;

public class PathTransitionDemoo extends Application {

@Override // Override the start method in the Application class

public void start(Stage primaryStage) {

// Create a pane 

Pane pane = new Pane();



// Create a rectangle

Rectangle rectangle = new Rectangle (0, 0, 25, 50);

rectangle.setFill(Color.ORANGE);



// Create a circle

Circle circle = new Circle(125, 100, 50);

circle.setFill(Color.WHITE);

circle.setStroke(Color.BLACK);



// Add circle and rectangle to the pane

pane.getChildren().add(circle);

pane.getChildren().add(rectangle);



// Create a path transition 

PathTransition pt = new PathTransition();

pt.setDuration(Duration.millis(4000));

pt.setPath(circle);

pt.setNode(rectangle);

pt.setOrientation(

  PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);

pt.setCycleCount(Timeline.INDEFINITE);

pt.setAutoReverse(true);

pt.play(); // Start animation 



circle.setOnMousePressed(e -> pt.pause());

circle.setOnMouseReleased(e -> pt.play());



// Create a scene and place it in the stage

Scene scene = new Scene(pane, 250, 200);

primaryStage.setTitle("PathTransitionDemo"); // 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);

}

}

使用以上範例以及JAVAFX
求解阿各位大神..

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答