Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.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
使用场景编辑器向JAVAFX FXML应用程序添加自定义窗格类_Java_Javafx_Import_Scenebuilder - Fatal编程技术网

使用场景编辑器向JAVAFX FXML应用程序添加自定义窗格类

使用场景编辑器向JAVAFX FXML应用程序添加自定义窗格类,java,javafx,import,scenebuilder,Java,Javafx,Import,Scenebuilder,好的,我有一个自定义窗格类,我想从FXML内部引用它。当我尝试将node类更改为BallPane时,它会说它不存在 import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.beans.property.DoubleProperty; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx

好的,我有一个自定义窗格类,我想从FXML内部引用它。当我尝试将node类更改为BallPane时,它会说它不存在

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Duration;

public class BallPane extends Pane {

    public final double radius = 20;
    private double x = radius, y = radius;
    private double dx = 1, dy = 1;
    private Circle circle = new Circle(x, y, radius);
    private Timeline animation;

    public BallPane() {
        circle.setFill(Color.GREEN);
        getChildren().add(circle);
        animation = new Timeline(
                new KeyFrame(Duration.millis(50), e -> moveBall()));
        animation.setCycleCount(Timeline.INDEFINITE);
        animation.play(); // Start animation 
    }

    public void play() {
        animation.play();
    }

    public void pause() {
        animation.pause();
    }

    public void increaseSpeed() {
        animation.setRate(animation.getRate() + 0.1);
    }

    public void decreaseSpeed() {
        animation.setRate(
                animation.getRate() > 0 ? animation.getRate() - 0.1 : 0);
    }

    public DoubleProperty rateProperty() {
        return animation.rateProperty();
    }

    protected void moveBall() {
        // Check boundaries 
        if (x < radius || x > getWidth() - radius) {
            dx *= -1; // Change ball move direction 
        }
        if (y < radius || y > getHeight() - radius) {
            dy *= -1; // Change ball move direction 
        }

        // Adjust ball position 
        x += dx;
        y += dy;
        circle.setCenterX(x);
        circle.setCenterY(y);
    }
}

我缺少什么?

不要使用默认包;它不能很好地与FXML配合使用(无论如何都强烈反对)。把你的类放在一个命名的包中。是的,这是一个很好的惯例。谢谢但它不能解决我的问题?仍在获取javafx.fxml.LoadException:BallPane不是有效的类型。/FXMLDocument.fxml:11显然,当v8退出时,我一直在使用严重过时的场景编辑器(v2)。fxml文件中是否有相应的
import
?不,我没有,但现在我有了,它可以正常工作。谢谢
    <BallPane layoutX="14.0" layoutY="14.0" prefHeight="334.0" prefWidth="462.0" />
@FXML
BallPane bpane;