Bonjour,

J'ai deux classes qui héritent de JFrame et qui écoutent les actions faites par la souris. Grâce à ActionPerformed je peux voir que l'information arrive à une classe et pas dans l'autre. Il n'y a pas de différences majeures entre le code de ces deux classes.

Pouvez vous m'aider s'il vous plaît?


La classe qui reçoit l'information avec ActionPerformed
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
import javax.swing.JFrame;
import javax.swing.Box;
import javax.swing.JScrollPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
//Fenetre Principal 
public class Frame1 extends JFrame implements ActionListener{
 
	public int numPict;//numéro image
	public Player p;//information joueur
	public Picture1 img;//affichage de l'image
	public Information inf;//affichage des informatioons
	public MysteryWord mw; //affichage du mot
 
 
  public Frame1(){
 
	this.numPict = 0;
	this.img = new Picture1(0);
    this.setTitle("Pendu");
    this.setSize(900, 600);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
 
 
    Panel1 keybP = new Panel1();
    Button1[] b = new Button1[26];//Boutons du clavier
    for(int i =0; i< 26; i++) {
    	char c = (char)(65 + i);
    	b[i] = new Button1(c);
    	b[i].addActionListener(this);
    	keybP.add(b[i]);
    }
 
    Information inf = new Information("Patrick", 20, 100);
    JScrollPane jsp = new JScrollPane(inf);
    MysteryWord mw = new MysteryWord("***************");
    JScrollPane jsp2 = new JScrollPane(mw);
 
 
    Box b0 = Box.createVerticalBox();//Nom, Nombre d'essai, Points
    b0.add(jsp);
 
 
 
    Box b1 = Box.createHorizontalBox();
    b1.add(b0);
 
 
    Box b4 = Box.createVerticalBox();//MOT A DEVINER
    b4.add(b1);
    b4.add(jsp2);
 
 
    Box b2 = Box.createHorizontalBox();//Image
    b2.add(b4);
    b2.add(this.img);
 
 
    Box b3 = Box.createVerticalBox();//Clavier
    b3.add(b2);
    b3.add(keybP);
 
 
 
    this.getContentPane().add(b3);
    this.setVisible(true);
  }
 
 
 
  public void setPicture(int n) {
	  this.numPict = n;
 
  }
 
  public void actionPerformed(ActionEvent arg0) {      
	  System.out.println("Jentends");
	  this.img.setPicture1(3);
	  System.out.println(this.numPict);
	  this.img.repaint();
 
  } 
 
}
La classe bouton qui marche avec cette classe
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
import javax.swing.JButton;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
 
public class Button1 extends JButton implements MouseListener{
 
	public char c;
 
	public Button1(char c) {
		String s = ""+c;
		this.setText(s);
		this.c = c;
		this.addMouseListener(this);
	}
 
	public char getValue() {
		return this.c;
	}
 
	public void mouseClicked(MouseEvent event) { 
		System.out.print(c);
		this.setEnabled(false);
 
	}
 
	public void mouseEntered(MouseEvent event) {
 
	}
 
	public void mouseExited(MouseEvent event) {
 
	}
 
	public void mousePressed(MouseEvent event) { }
	  public void mouseReleased(MouseEvent event) { }       
 
	}


La classe qui ne reçoit pas l'info du clique chez elle
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Box;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
 
//Fenetre Principal 
public class FirstFrame extends JFrame implements ActionListener{
 
	public JLabelP go;
	public JLabelP about;
 
 
  public FirstFrame(){
	  this.setTitle("Pendu");
	  this.setSize(900, 600);
	  this.setLocationRelativeTo(null);
	  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	  this.go = new JLabelP("Jouer");
	  this.about = new JLabelP("A propos");
 
 
	  Picture1 img = new Picture1(8);
 
	  JPanel a = new JPanel();
	  JPanel b = new JPanel();
 
 
	  a.add(this.go);
	  b.add(this.about);
 
	  Box b1 = Box.createVerticalBox();
	  b1.add(a);
	  b1.add(b);
 
	  Box b2 = Box.createHorizontalBox();
	  b2.add(b1);
	  b2.add(img);
 
	  this.add(b2);
	  this.setVisible(true);
 
 
 
  }
 
 
  public void actionPerformed(ActionEvent evt) {
	  System.out.println("yo");
}
}
Et le JLabel qui lui est associé:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
//Panneau dans le menu principal qui écoute les cliques
import javax.swing.JLabel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.Font;
 
 
public class JLabelP extends JLabel implements MouseListener{
 
	public JLabelP(String s) {
		this.setText(s);
		this.setFont(new Font("Serif", Font.PLAIN, 30));
		this.addMouseListener(this);
	}
 
 
 
 
	public void mouseClicked(MouseEvent event) { 
		System.out.print("*");
 
	}
 
	public void mouseEntered(MouseEvent event) {
 
	}
 
	public void mouseExited(MouseEvent event) {
 
	}
 
	public void mousePressed(MouseEvent event) { }
 
  public void mouseReleased(MouseEvent event) { }       
	}
J'ai aussi essayé d'interchanger les boutons ça ne marchait pas non plus.