Skip to content
Snippets Groups Projects
Commit 2b963075 authored by Sami Zouari's avatar Sami Zouari
Browse files

question 5 finie

parent fd7e6fab
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment