From c169ba06233fb3707eeb3bef843415326f5e89cf Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 30 Apr 2022 16:38:56 +0200 Subject: [PATCH] debut listener --- Case.java | 5 ++++- Grille.java | 5 +++-- Listener.java | 26 ++++++++++++++++++++++++++ SwitchVisible.java | 25 +++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Listener.java create mode 100644 SwitchVisible.java diff --git a/Case.java b/Case.java index 62876e8..873c043 100644 --- a/Case.java +++ b/Case.java @@ -1,11 +1,12 @@ import javax.swing.*; import java.awt.*; -public class Case extends JComponent { +public class Case extends JPanel { private JPanel panel = new JPanel(); private int entourage; private boolean visible; private boolean minee; + private Listener listener; public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) { super(); @@ -13,6 +14,8 @@ public class Case extends JComponent { this.visible=visible; this.minee=minee; this.panel.setSize(caseSize); + this.listener = new Listener(); + panel.addMouseListener(listener); GridLayout unique = new GridLayout(1,1); this.panel.setLayout(unique); diff --git a/Grille.java b/Grille.java index 9c23631..67f22c1 100644 --- a/Grille.java +++ b/Grille.java @@ -2,7 +2,7 @@ import javax.swing.*; import java.awt.*; import java.util.Random; -public class Grille extends JComponent { +public class Grille extends JPanel { private Dimension grilleSize=new Dimension(0,0); private JPanel grille= new JPanel(); @@ -23,7 +23,7 @@ public class Grille extends JComponent { // Initialisation : les cases sont cachées boolean[] visible = new boolean[lignes*colonnes]; for (int i=0; i