首页 > 解决方案 > 类 Circle javafx.scene.shape.* 中的构造函数 Circle 存在问题;

问题描述

我正在尝试从标准 javafx.scene.shape 创建一个简单的圆圈。* 班级。当我尝试编译程序时,我收到以下错误消息。我正在使用 Java 8.291!我尝试用一​​个参数创建一个圆圈,但错误消息告诉我不需要参数。

test2.java:33: error: constructor Circle in class Circle cannot be applied to given types;
           Circle circleA = new Circle(20);
                            ^
**required: no arguments
found: int**
reason: actual and formal argument lists differ in length
test2.java:35: error: no suitable method found for addAll(Circle)
           rootNode.getChildren().addAll(circleA);
                                 ^
method Collection.addAll(Collection<? extends Node>) is not applicable
 (argument mismatch; Circle cannot be converted to Collection<? extends Node>)
method List.addAll(Collection<? extends Node>) is not applicable
 (argument mismatch; Circle cannot be converted to Collection<? extends Node>)
method ObservableList.addAll(Node...) is not applicable
 (varargs mismatch; Circle cannot be converted to Node)
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors
import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.geometry.*;
import javafx.scene.transform.*;
import javafx.scene.shape.*;

public class test2 extends Application{

    public static void main(String[] args){
    
        // Start the JavaFX application by calling launch().
        launch(args);
    }

    // Override the start() method.
    public void start(Stage myStage){
        myStage.setTitle("Transformer");
        FlowPane rootNode = new FlowPane(40, 40);
        rootNode.setAlignment(Pos.CENTER);
        Scene myScene = new Scene(rootNode, 500, 200);
        myStage.setScene(myScene);
        Circle circleA = new Circle(20);
        rootNode.getChildren().addAll(circleA);
        myStage.show(); 
    }
}

标签: javafxjavafx-8

解决方案


推荐阅读