Lecho
Lecho

Reputation: 5

JavaFX Circle() shape not showing when running program

I've created a class xxxCircle that has method draw(). This draw method is essentially supposed to draw a circle using JavaFX's predefined class Circle (javafx.scene.shape.Circle). When I run the program, there aren't any errors but the circle just isn't displayed. What can I do to fix this?

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);
    }
}

Upvotes: 0

Views: 1073

Answers (1)

Raw
Raw

Reputation: 506

Your are missing to add the Circle

Group group = new Group();
group.getChildren().add(circle1);  <---missing

Scene circScene = new Scene(group, 500, 500);
circle1.draw();
primaryStage.setScene(circScene);

primaryStage.show();

Upvotes: 1

Related Questions