debut listener
This commit is contained in:
parent
79df7ffb1a
commit
c169ba0623
@ -1,11 +1,12 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class Case extends JComponent {
|
public class Case extends JPanel {
|
||||||
private JPanel panel = new JPanel();
|
private JPanel panel = new JPanel();
|
||||||
private int entourage;
|
private int entourage;
|
||||||
private boolean visible;
|
private boolean visible;
|
||||||
private boolean minee;
|
private boolean minee;
|
||||||
|
private Listener listener;
|
||||||
|
|
||||||
public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) {
|
public Case(Dimension caseSize, boolean visible, boolean minee, int entourage) {
|
||||||
super();
|
super();
|
||||||
@ -13,6 +14,8 @@ public class Case extends JComponent {
|
|||||||
this.visible=visible;
|
this.visible=visible;
|
||||||
this.minee=minee;
|
this.minee=minee;
|
||||||
this.panel.setSize(caseSize);
|
this.panel.setSize(caseSize);
|
||||||
|
this.listener = new Listener();
|
||||||
|
panel.addMouseListener(listener);
|
||||||
|
|
||||||
GridLayout unique = new GridLayout(1,1);
|
GridLayout unique = new GridLayout(1,1);
|
||||||
this.panel.setLayout(unique);
|
this.panel.setLayout(unique);
|
||||||
|
@ -2,7 +2,7 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class Grille extends JComponent {
|
public class Grille extends JPanel {
|
||||||
private Dimension grilleSize=new Dimension(0,0);
|
private Dimension grilleSize=new Dimension(0,0);
|
||||||
private JPanel grille= new JPanel();
|
private JPanel grille= new JPanel();
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public class Grille extends JComponent {
|
|||||||
// Initialisation : les cases sont cachées
|
// Initialisation : les cases sont cachées
|
||||||
boolean[] visible = new boolean[lignes*colonnes];
|
boolean[] visible = new boolean[lignes*colonnes];
|
||||||
for (int i=0; i<lignes*colonnes;i++){
|
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
|
// On place les cases à leur état actuel dans la grille
|
||||||
AffichePlateau(lignes*colonnes, caseSize, entourage, visible, minee);
|
AffichePlateau(lignes*colonnes, caseSize, entourage, visible, minee);
|
||||||
}
|
}
|
||||||
|
26
Listener.java
Normal file
26
Listener.java
Normal 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
25
SwitchVisible.java
Normal 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){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user