fix: dashboard et mis GObserver

This commit is contained in:
2025-11-09 13:48:34 +01:00
parent 49e07870e1
commit ea260adbc7
2 changed files with 24 additions and 9 deletions

View File

@@ -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<Boolean> fn, Color bg, int width, int height, int x, int y)
private static boolean isPaused = false;
public Dashboard(Car car, String title, Supplier<Boolean> 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<Boolean> 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();
}
};