Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. public void start(Stage stage) {
  2. stage.setTitle("Dots!");
  3. // TODO: Your code starts here
  4. currentColor = Color.RED;
  5. dotList = new SinglyLinkedList<Dot>();
  6. Pane pane = new Pane();
  7. pane.setPrefSize(SIZE, SIZE);
  8. Dot dot = new Dot(50 ,50);
  9. dot.setFill(currentColor);
  10. //dotList.add(dot);
  11. //pane.getChildren().add(dot);
  12. Scene scene = new Scene(pane);
  13. stage.setScene(scene); // Place the scene in the stage
  14.  
  15. pane.setOnKeyPressed(e -> {
  16. switch (e.getCode()) {
  17. case DIGIT1: currentColor = Color.RED; break;
  18. case DIGIT2: currentColor = Color.BLUE; break;
  19. case DIGIT3: currentColor = Color.GREEN; break;
  20. case NUMPAD1: currentColor = Color.RED; break;
  21. case NUMPAD2: currentColor = Color.BLUE; break;
  22. case NUMPAD3: currentColor = Color.GREEN; break;
  23. default:
  24. break;
  25. }
  26. });
  27. pane.requestFocus();
  28.  
  29. pane.setOnMouseClicked(e -> {
  30. double x = e.getX();
  31. double y = e.getY();
  32. int index = 0;
  33. int size = dotList.size();
  34. if (size !=0 && index == size) {
  35. Dot check = dotList.get(index);
  36. if (check.contains(x, y)) {
  37. dotList.remove(index);
  38. pane.getChildren().remove(index); //This is may be wrong
  39. size = dotList.size();
  40. }
  41. index++;
  42. }
  43. Dot newDot = new Dot(x ,y);
  44. dotList.add(newDot);
  45. pane.getChildren().add(newDot); ///This adds a new dot, this works
  46.  
  47.  
  48. });
  49. pane.requestFocus();
  50.  
  51. // Your code ends here
  52.  
  53. stage.show(); // makes the window visible to the user
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement