From 2b96307567460d43ae7b2b5ab879e41b6cc44cf1 Mon Sep 17 00:00:00 2001 From: Sami Zouari <sami.zouari@univ-lorraine.fr> Date: Thu, 27 Jan 2022 10:17:32 +0100 Subject: [PATCH] question 5 finie --- .../java/com/example/testig/Ecouteur.java | 33 +++++++++++++++++++ .../com/example/testig/HelloApplication.java | 20 ++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/testig/Ecouteur.java b/src/main/java/com/example/testig/Ecouteur.java index 8b6131d..4326fc1 100644 --- a/src/main/java/com/example/testig/Ecouteur.java +++ b/src/main/java/com/example/testig/Ecouteur.java @@ -2,10 +2,43 @@ package com.example.testig; import javafx.event.ActionEvent; import javafx.event.EventHandler; +import javafx.scene.control.Label; + +import java.util.Random; public class Ecouteur implements EventHandler<ActionEvent> { + + private int compteur = 1; + private Label label1; + private Label label2; + private Label label3; + private Random random = new Random(); + + public Ecouteur(){} + + public Ecouteur(Label l1, Label l2, Label l3){ + + this.label1 = l1; + this.label2 = l2; + this.label3 = l3; + + } + @Override public void handle(ActionEvent actionEvent) { + System.out.println("Bienvenue dans le Jeu !"); + System.out.println("Nombre de clicks : " + compteur); + compteur += 1; + + int n, x, y; + n = random.nextInt(7); + x = random.nextInt(7); + y = random.nextInt(7); + + label1.setText(""+ n); + label2.setText(""+ x); + label3.setText(""+ y); + } } diff --git a/src/main/java/com/example/testig/HelloApplication.java b/src/main/java/com/example/testig/HelloApplication.java index 2aee35e..2653ed9 100644 --- a/src/main/java/com/example/testig/HelloApplication.java +++ b/src/main/java/com/example/testig/HelloApplication.java @@ -1,10 +1,14 @@ package com.example.testig; import javafx.application.Application; +import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; import javafx.stage.Stage; import java.io.IOException; @@ -13,15 +17,23 @@ public class HelloApplication extends Application { @Override public void start(Stage stage) throws IOException { - + /* question 1 */ stage.setTitle("Titre TP!"); BorderPane border = new BorderPane(); Button bouton = new Button("Jouer"); - border.setBottom(bouton); - bouton.setOnAction(new Ecouteur()); + HBox box = new HBox(); + Label l1 = new Label("1"); + Label l2 = new Label("1"); + Label l3 = new Label("1"); - stage.setScene(new Scene(border, 400, 400)); + box.getChildren().addAll(l1, l2, l3); + + border.setCenter(box); + border.setBottom(bouton); + bouton.setOnAction(new Ecouteur(l1,l2,l3)); + Scene scene = new Scene(border, 400, 400); + stage.setScene(scene); stage.show(); } -- GitLab