Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的过渡期没有';行不通_Java_Javafx - Fatal编程技术网

Java 我的过渡期没有';行不通

Java 我的过渡期没有';行不通,java,javafx,Java,Javafx,在这段代码中,当调用转换的play()方法(PathTransition pt;)时,程序隐藏橙色矩形,不显示任何转换。它没有语法错误。我试着让矩形绕着圆圈转 import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.control.*; import javafx

在这段代码中,当调用转换的
play()
方法
(PathTransition pt;)
时,程序隐藏橙色矩形,不显示任何转换。它没有语法错误。我试着让矩形绕着圆圈转

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.control.*;
import javafx.event.Event;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.util.Duration;

public class Test__javafx extends Application{
    public void start(Stage stage) {
        Pane p = new Pane();
        Button b = new Button("Play");
        b.setStyle("-fx-background-radius: 3em;" + 
                "-fx-background-color: #66a3ff;" +
                "-fx-min-width: 120;" +
                "-fx-min-height: 40;" +
                "-fx-max-width: 120;" +
                "-fx-min-height: 40;" +
                "-fx-cursor: hand;" + 
                "-fx-text-fill: white;");
        b.setLayoutX(320);
        b.setLayoutY(400);


        b.setOnAction((ActionEvent event) -> {

            Circle big = new Circle();
       // create rectangle for big circle
       Rectangle bigRec = new Rectangle();
            Circle circ = new Circle();
            Rectangle r = new Rectangle();
            //event for small rectangle
            r.setWidth(20);
            r.setHeight(30);
            r.setLayoutX(362);
            r.setLayoutY(335);

            r.setArcWidth(5);
            r.setArcHeight(5);
            r.setStyle("-fx-fill: #ff9933;" +
                    "-fix-stroke-width: 20;" +
                    "-fix-stroke: #ff4d4d;");

            //event for small circle
            circ.setStyle("-fx-fill: #88ff4d;" +
                    "-fx-stroke-width: 12;" +
                    "-fx-stroke: #3399ff;");
            circ.setCenterX(370);
            circ.setCenterY(400);
            circ.setRadius(50);

            // event for big circle's rectangle
             bigRec.setLayoutX(205);
            bigRec.setLayoutY(375);
            bigRec.setWidth(30);
            bigRec.setHeight(20);
            bigRec.setArcWidth(5);
            bigRec.setArcHeight(5);
            bigRec.setStyle("-fx-fill: #ff9933;" +
                    "-fix-stroke-width: 20;" +
                    "-fix-stroke: #ff4d4d;");

            // big circle
            big.setStyle("-fx-fill: #88ff4d;" +
                    "-fx-stroke-width: 12;" +
                    "-fx-stroke: #3399ff;");
            big.setCenterX(370);
            big.setCenterY(400);
            big.setRadius(150);
            p.getChildren().addAll(big, bigRec, circ, r);
            // transition for small circle and rectangle

            PathTransition pt = new PathTransition();
            pt.setDuration(Duration.millis(2000));
            pt.setPath(bigRec);
            pt.setNode(bigRec);
            pt.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
            pt.setCycleCount(Timeline.INDEFINITE);
            pt.setAutoReverse(false);
           // if you comment the play method it shows the rectangle
             // but not any transitions obviously
           pt.play();

             PathTransition pt2 = new PathTransition();
            pt2.setDuration(Duration.millis(2000));
            pt2.setPath(circ);
            pt2.setNode(r);
            pt2.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
            pt2.setCycleCount(Timeline.INDEFINITE);
            pt2.setAutoReverse(false);
             // if you comment the play method it shows the rectangle
             // but not any transitions obviously
           pt2.play();

        });
        p.getChildren().add(b);
        p.setStyle("-fx-background-color: #88ff4d;");
        Scene s = new Scene(p, 750, 650);
        stage.setScene(s);
        stage.show(); 
    }
    // launch Application
    public static void main(String[] args) {
        Application.launch(args);
    } 
}

在第一次
路径转换中
,您将路径和节点都设置为bigRec。将路径设置为big而不是bigRec

PathTransition pt = new PathTransition();
pt.setDuration(Duration.millis(2000));
pt.setPath(big); // Make this change
pt.setNode(bigRec);
pt.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
pt.setCycleCount(Timeline.INDEFINITE);
pt.setAutoReverse(false);
同时,在为矩形设置的坐标处进行转换。要查看圆上的矩形,请从矩形中删除布局值。即删除以下代码

//Code to be removed
bigRec.setLayoutX(205);
bigRec.setLayoutY(375);

r.setLayoutX(362);
r.setLayoutY(335);

我不知道我怎么会错过这样一个错误。非常感谢。@Ibrahim Java如果回答了您的问题,请标记它以帮助未来的用户。