[英]Add a Rectangle to root in javafx
i try to create some shapes of javafx library.. 我尝试创建一些形状的javafx库..
So, in the 'start' method, when i create a new circle and i add it to the root, i don't have any problem : 所以,在'start'方法中,当我创建一个新的圆圈并将其添加到根时,我没有任何问题:
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 800, 600, Color.LIGHTBLUE);
primaryStage.setScene(scene);
Circle cercle = new Circle();
cercle.setCenterX(300);
cercle.setCenterY(200);
cercle.setRadius(100);
cercle.setFill(Color.YELLOW);
cercle.setStroke(Color.ORANGE);
cercle.setStrokeWidth(5);
root.getChildren().add(cercle);
primaryStage.show();
}
but, when i try to do this with a rectangle, the compiler doesn't accept, and draw a red line under the 'add' method 但是,当我尝试使用矩形执行此操作时,编译器不接受,并在'add'方法下绘制一条红线
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 800, 600, Color.LIGHTBLUE);
primaryStage.setScene(scene);
Rectangle rectangle = new Rectangle();
rectangle.setX(300);
rectangle.setY(200);
rectangle.setWidth(300);
rectangle.setHeight(200);
rectangle.setFill(Color.GREEN);
rectangle.setStroke(Color.DARKGREEN);
rectangle.setStrokeWidth(5);
rectangle.setArcHeight(30);
rectangle.setArcWidth(30);
root.getChildren().add(rectangle);
primaryStage.show();
}
The compiler say : 编译器说:
The method add(Node) in the type List is not applicable for the arguments (Rectangle)
类型List中的方法add(Node)不适用于参数(Rectangle)
I see this in other programs, it work normally. 我在其他程序中看到这一点,它正常工作。
Note: I use eclipse luna and jdk 8 注意:我使用eclipse luna和jdk 8
com.sun.javafx.geom.Rectangle
is a JDK internal class and does NOT extend the Node
class but you should not be using internal classes anyway. com.sun.javafx.geom.Rectangle
是一个JDK内部类,不扩展Node
类,但你不应该使用内部类。 Remove this internal import and instead replace with: 删除此内部导入,而不是替换为:
import javafx.scene.shape.Rectangle
Use 采用
import javafx.scene.shape.Rectangle;
instead of 代替
import java.awt.Rectangle;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.