Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test060511 extends Application {
- private int score = 0;
- @Override
- public void start(Stage primaryStage) {
- Group root = new Group();
- Scene scene = new Scene(root, 800, 600);
- Text t = new Text();
- randomNew(root, 10);
- root.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent event) {
- Circle c = (Circle) event.getTarget();
- root.getChildren().remove(c);
- root.getChildren().remove(t);
- score++;
- t.setCache(true);
- t.setX(10.0);
- t.setY(30.0);
- t.setFill(Color.RED);
- t.setText("Score: " + score);
- t.setFont(Font.font(null, FontWeight.BOLD, 16));
- root.getChildren().add(t);
- randomNew(root, 1);
- }
- });
- primaryStage.setTitle("Hello World!");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- private void randomNew(Group root, int quantity) {
- for (int i = 0; i < quantity; i ++) {
- Circle circle=new Circle(15, Color.GOLD);
- circle.setCenterX(Math.random() * 800);
- circle.setCenterY(Math.random() * 600);
- root.getChildren().add(circle);
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement