2

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;
    }
}
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Deezee
  • 51
  • 1
  • 9
  • Could you post some source code to give us a better idea? – Alper Akture Oct 14 '15 at 04:41
  • Hmm .. doesn't your IDE show a choice of how to solve the errror? It's either adding the abstract modifier _or_ implementing the missing abstract method. BTW, a beginner's must-read: http://stackoverflow.com/tags/java/info - there are references to relevant tutorials :-) And naming conventions ... – kleopatra Oct 14 '15 at 09:54
  • this particular case is a rather weird: the abstract method that needs implementation is public and deprecated `impl_configShape` which concrete extensions like f.i. Line implement to return a shape of a type in internal packages ... it's undocumented (aka: doesn't exist) – kleopatra Oct 14 '15 at 13:23
  • Thank you for your response Kleopatra! I'll definitely fix my naming convention, I threw that together really quick to put an example of what I was trying to do and managed to miss that class name. I also just noticed that I mistakenly screwed the method up, but that's a different issue. There's got to be a way to take multiple shapes and combine them into a class in a way they can retain their identity. I did manage to create a class that I can make a complex shape and pass it through via 'return'. But all of my shapes lose their independence and I no longer can modify them. – Deezee Oct 14 '15 at 22:01
  • from your code extending shape here is somehow useless, and the `Shape` class you created is different from the `Shape` class that returns from the method, what is your outcome? and what is really your problem? – Elltz Oct 17 '15 at 11:56

1 Answers1

1

Best way to deal with this is to use a layout as a container for all of your objects (i.e. Rectangle, Circle, etc.) and create field or properties you can alter after the fact. So create a class that extends some type of layout (HBox, VBox, GridPane, etc.) and place all your shape objects in there. If you need to subtract to one shape from another and it needs to be dynamic, create a method that'll rebuild the shape as it is called.

Deezee
  • 51
  • 1
  • 9