Advertisement
Guest User

Untitled

a guest
Jun 17th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. public class Test060511 extends Application {
  2.  
  3. private int score = 0;
  4.  
  5. @Override
  6. public void start(Stage primaryStage) {
  7. Group root = new Group();
  8. Scene scene = new Scene(root, 800, 600);
  9. Text t = new Text();
  10.  
  11. randomNew(root, 10);
  12.  
  13. root.setOnMouseClicked(new EventHandler<MouseEvent>() {
  14. @Override
  15. public void handle(MouseEvent event) {
  16.  
  17. Circle c = (Circle) event.getTarget();
  18. root.getChildren().remove(c);
  19. root.getChildren().remove(t);
  20.  
  21. score++;
  22. t.setCache(true);
  23. t.setX(10.0);
  24. t.setY(30.0);
  25. t.setFill(Color.RED);
  26. t.setText("Score: " + score);
  27. t.setFont(Font.font(null, FontWeight.BOLD, 16));
  28.  
  29. root.getChildren().add(t);
  30. randomNew(root, 1);
  31. }
  32. });
  33.  
  34. primaryStage.setTitle("Hello World!");
  35. primaryStage.setScene(scene);
  36. primaryStage.show();
  37. }
  38.  
  39. private void randomNew(Group root, int quantity) {
  40. for (int i = 0; i < quantity; i ++) {
  41. Circle circle=new Circle(15, Color.GOLD);
  42. circle.setCenterX(Math.random() * 800);
  43. circle.setCenterY(Math.random() * 600);
  44. root.getChildren().add(circle);
  45. }
  46. }
  47.  
  48. /**
  49. * @param args the command line arguments
  50. */
  51. public static void main(String[] args) {
  52. launch(args);
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement