Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void start(Stage stage) {
- stage.setTitle("Dots!");
- // TODO: Your code starts here
- currentColor = Color.RED;
- dotList = new SinglyLinkedList<Dot>();
- Pane pane = new Pane();
- pane.setPrefSize(SIZE, SIZE);
- Dot dot = new Dot(50 ,50);
- dot.setFill(currentColor);
- //dotList.add(dot);
- //pane.getChildren().add(dot);
- Scene scene = new Scene(pane);
- stage.setScene(scene); // Place the scene in the stage
- pane.setOnKeyPressed(e -> {
- switch (e.getCode()) {
- case DIGIT1: currentColor = Color.RED; break;
- case DIGIT2: currentColor = Color.BLUE; break;
- case DIGIT3: currentColor = Color.GREEN; break;
- case NUMPAD1: currentColor = Color.RED; break;
- case NUMPAD2: currentColor = Color.BLUE; break;
- case NUMPAD3: currentColor = Color.GREEN; break;
- default:
- break;
- }
- });
- pane.requestFocus();
- pane.setOnMouseClicked(e -> {
- double x = e.getX();
- double y = e.getY();
- int index = 0;
- int size = dotList.size();
- if (size !=0 && index == size) {
- Dot check = dotList.get(index);
- if (check.contains(x, y)) {
- dotList.remove(index);
- pane.getChildren().remove(index); //This is may be wrong
- size = dotList.size();
- }
- index++;
- }
- Dot newDot = new Dot(x ,y);
- dotList.add(newDot);
- pane.getChildren().add(newDot); ///This adds a new dot, this works
- });
- pane.requestFocus();
- // Your code ends here
- stage.show(); // makes the window visible to the user
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement