From ea260adbc76d4669781dfa2112c71f6901553287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Sun, 9 Nov 2025 13:48:34 +0100 Subject: [PATCH] fix: dashboard et mis GObserver --- src/Dashboard.java | 20 +++++++++++--------- src/GObserver.java | 13 +++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 src/GObserver.java diff --git a/src/Dashboard.java b/src/Dashboard.java index 52dbb73..f588f5c 100644 --- a/src/Dashboard.java +++ b/src/Dashboard.java @@ -1,7 +1,7 @@ import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.function.Function; + import java.util.function.Supplier; import javax.swing.JButton; @@ -18,7 +18,9 @@ public class Dashboard extends GameView private final JButton button; private final Car car; - public Dashboard(Car car, String title, Supplier fn, Color bg, int width, int height, int x, int y) + private static boolean isPaused = false; + + public Dashboard(Car car, String title, Supplier fn, int width, int height, int x, int y) { super("Dashboard: " + title, width, height, x, y); @@ -27,31 +29,31 @@ public class Dashboard extends GameView this.button = new JButton(); // ajout background - super.window.setBackground(bg); + setBackground(car.getColor()); init(fn); - super.window.add(label); - super.window.add(button); + frame.add(label); + frame.add(button); } // fonction uniquement pour l'affichage dynamique - public void updateButtonText(boolean isPaused) + private void updateButtonText() { button.setText(isPaused ? "En Pause" : "En Cours"); } private void init(Supplier fn) { - // de base, le jeu est en cours - updateButtonText(false); + updateButtonText(); // classe pour le bouton MouseAdapter ma = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - fn.get(); + isPaused = fn.get(); + updateButtonText(); } }; diff --git a/src/GObserver.java b/src/GObserver.java new file mode 100644 index 0000000..6ad48c9 --- /dev/null +++ b/src/GObserver.java @@ -0,0 +1,13 @@ +@FunctionalInterface +/** + * L'interface utilisée pour Game. + */ +public interface GObserver +{ + /** + * + * @return true si la fonction s'est bien passé sinon false (le programme va se + * stopper) + */ + public boolean apply(); +}