Sunday, April 19, 2015

JavaFX adding spots to linked list


For javafx code, I made a KeyEvent and a MouseEvent where the user clicks on the screen and a spot will appear (spot is an inner class that I defined), but how can I add each spot that appears on the screen into my dotList? I am not sure how to do that?



Java Code:



public void start(Stage stage) {
dotList = new SinglyLinkedList<>();
Pane root = new Pane();

root.setOnMouseClicked(event ->
root.getChildren().add(
new Spot(
event.getX(),
event.getY()
)
)
);

Scene scene = new Scene(root, SIZE, SIZE, Color.BLACK);
scene.setOnKeyTyped(event -> {
switch (event.getCharacter()) {
case "1":
currentColor = Color.RED;
break;
case "2":
currentColor = Color.BLUE;
break;
case "3":
currentColor = Color.GREEN;
}
});

stage.setScene(scene);
stage.show();
}


No comments:

Post a Comment