I'm very green when it comes to JavaFX and programming in generally, especially object oriented. I've worked in the Main()
method initially and have been able to create more complex shapes using multiple Shapes
and employing Unions and Subtractions. Now I'd like to be able to create a new Class/Object that I can call on to reuse that code.
I thought it'd be along the lines of creating a "complexshape" class and extending Shapes. Then build up my complex shape the same as I did in main()
. Then go back to main and Instantiate an object via a constructor and place the object into my layout via layout.getChildren().add(objectname);
But my IDE tells me the "complexshape" class must be abstract, Which I have a partial clue what that means. But I'm not exactly sure what to do about it.
Any ideas on why my logic is wrong here?
Main.java
package sample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
Scene scene = new Scene(root, 100,100,Color.WHITE);
complexShape A = new complexShape();
root.getChildren().add(A);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
complexShape.java
package sample;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
public class complexShape extends Shape {
public Shape complesShape() {
Circle A = new Circle(50,50,10);
Rectangle B = new Rectangle(50,50,100,10);
Shape C = Shape.union(A, B);
C.setFill(Color.RED);
return C;
}
}