I`m trying to develop a javafx project in such a manner that the business logic and the view are seperated. Frankly, I don´t know if i realised it right.
My idea was to create a class view. Simplified it looks like this:
public class View extends Application {
private Pane screen = new Pane();
private Rectangle rect;
private Scene scene = new Scene(screen, 500, 500);
public View(){
rect = new Rectangle(10, 10, 100, 100);
rect.setFill(Color.WHITE);
rect.setStroke(Color.BLACK);
screen.getChildren().add(rect);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Rectangles");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
public void setColor() {
rect.setFill(Color.BROWN);
}
}
Objects of that class can be created and used in this way in the main method of another class including the bussiness logic:
View foo = new View();
foo.main(null);
Unfortunately, I can´t change its attributes afterwards. Therefore, this statement doesn´t have any effect.
foo.setColor();
Like I said, maybe this is a wrong approach. I´m not very familiar with javafx, so please indulge me.