diff --git a/src/main/java/com/example/testig/Ecouteur.java b/src/main/java/com/example/testig/Ecouteur.java index 8b6131d7abdc4522216953d4a48306ce6df920d9..4326fc1bf24ae9e94f66b8695ba935eb5db0708e 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 2aee35e15da07d46983a5f264deb9354c8d9b6c3..2653ed9c9c83600f54cf05f04b85c53c19af109f 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(); }