debut listener

This commit is contained in:
Haïssous Kayyissa 2022-04-30 16:38:56 +02:00
parent 79df7ffb1a
commit c169ba0623
4 changed files with 58 additions and 3 deletions

View File

@ -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);

View File

@ -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<lignes*colonnes;i++){
visible[i]=true;
visible[i]=false;
}
@ -262,6 +262,7 @@ public class Grille extends JComponent {
}
}
// On place les cases à leur état actuel dans la grille
AffichePlateau(lignes*colonnes, caseSize, entourage, visible, minee);
}

26
Listener.java Normal file
View File

@ -0,0 +1,26 @@
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Listener implements MouseListener{
@Override
public void mouseClicked(MouseEvent evenement){
System.out.println("mouseClicked");
JPanel lb = (JPanel)evenement.getSource();
lb.setBackground(new Color(255, 255, 255));
}
public void mouseEntered(MouseEvent evenement){
System.out.println("mouseEntered");
}
public void mouseExited(MouseEvent evenement){
System.out.println("mouseExited");
}
public void mousePressed(MouseEvent evenement){
System.out.println("mousePressed");
}
public void mouseReleased(MouseEvent evenement){
System.out.println("mouseReleased");
}
}

25
SwitchVisible.java Normal file
View File

@ -0,0 +1,25 @@
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class SwitchVisible extends JComponent implements MouseListener {
public SwitchVisible() {
}
public void mouseClicked(MouseEvent evenement){
}
public void mouseEntered(MouseEvent evenement){
}
public void mouseExited(MouseEvent evenement){
}
public void mousePressed(MouseEvent evenement){
}
public void mouseReleased(MouseEvent evenement){
}
}