Inheritance 运行程序时未显示JavaFX Circle()形状
我创建了一个类Inheritance 运行程序时未显示JavaFX Circle()形状,inheritance,javafx,shapes,Inheritance,Javafx,Shapes,我创建了一个类xxxCircle,该类具有方法draw()。这个绘制方法本质上应该使用JavaFX的预定义类circle(JavaFX.scene.shape.circle)绘制一个圆。当我运行程序时,没有任何错误,只是没有显示圆圈。我能做些什么来解决这个问题 xxxCircle.java package sample; import javafx.scene.shape.Circle; public class xxxCircle extends xxxShape { doubl
xxxCircle
,该类具有方法draw()
。这个绘制方法本质上应该使用JavaFX的预定义类circle
(JavaFX.scene.shape.circle
)绘制一个圆。当我运行程序时,没有任何错误,只是没有显示圆圈。我能做些什么来解决这个问题
xxxCircle.java
package sample;
import javafx.scene.shape.Circle;
public class xxxCircle extends xxxShape {
double radius;
double xvalue;
double yvalue;
xxxCircle(double radius, double xvalue, double yvalue){
this.radius = radius;
this.xvalue = xvalue;
this.yvalue = yvalue;
}
public double getRadius(){
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public void setXvalue(double xvalue){
this.xvalue=xvalue;
}
public void setYvalue(double yvalue){
this.yvalue=yvalue;
}
public void draw(){
Circle circle = new Circle();
circle.setCenterX(xvalue);
circle.setCenterY(yvalue);
circle.setRadius(radius);
}
}
Main.java:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.shape.Circle;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.Group;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Circle test");
Scene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene);
xxxCircle circle1 = new xxxCircle(100,250,250);
Group group = new Group();
Scene circScene = new Scene(group, 500, 500);
circle1.draw();
primaryStage.setScene(circScene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
您缺少添加
的圆圈
Group group = new Group();
group.getChildren().add(circle1); <---missing
Scene circScene = new Scene(group, 500, 500);
circle1.draw();
primaryStage.setScene(circScene);
primaryStage.show();
Group Group=新组();
group.getChildren().add(圈1);实际上,您从未将圆
添加到场景图中(您只需创建它,然后将其丢弃)。我不确定xxxShape
是否是节点
的子类。根据描述,我得到的印象是这个类应该管理一个节点,而不是节点本身……当我尝试添加“group.getChildren().add(circle1);”时,它在circle1下面给我一个错误,说“error:(26,33)java:不兼容的类型:sample.xxxCircle无法转换为javafx.scene.node”