Bonjour tout le monde,

Voicie mon Probleme j'ai creer une class pour afficher mes smiley dans une boite de dialogue, quand je clique sur un smiley il doit se passer une action envoie d'un message ect... pour chaque smiley une action differente, mon probléme est que quand je clique il ne se passe rien comme si se n'etait pas un bouton.

ImageSmiley.java ma class image :

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
package code.ar.com.jkohen.awt;
 
import java.awt.*;
import java.awt.event.*;
 
public class ImageSmiley extends Canvas
{
    private Image img;
 
	private ActionListener actionListener;
	protected String action_command;
 
    public ImageSmiley(Image img)
    {
		this.img = img;
    }
 
    @Override
	public void paint(Graphics g)
    {
		g.drawImage(img, 0, 0, this);
    }
 
    @Override
	public Dimension getMinimumSize()
    {
		return getPreferredSize();
    }
 
    @Override
	public Dimension getPreferredSize()
    {
		int w, h;
 
		while ((w = img.getWidth(this)) == -1);
		while ((h = img.getHeight(this)) == -1);
 
		return new Dimension(w, h);
    }
 
	public void addActionListener(ActionListener smiley1)
    {
		if (null != smiley1)
		    actionListener = AWTEventMulticaster.add(actionListener, smiley1);
    }
 
    public void removeActionListener(ActionListener l)
    {
		if (null != l)
		    actionListener = AWTEventMulticaster.remove(actionListener, l);
    }
 
    public String getActionCommand()
    {
		return action_command;
    }
 
    public void setActionCommand(String action)
    {
		this.action_command = action;
    }
 
    protected void processActionEvent(ActionEvent e)
    {
		if (actionListener != null)
		    actionListener.actionPerformed(e);
    }
}
SmileyBox.java ma boite de dialogue avec mes actionlisteners :

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package code;
 
import java.awt.*;
import java.awt.event.*;
import code.ar.com.jkohen.awt.ImageButton;
import code.ar.com.jkohen.awt.ImageSmiley;
import code.ar.com.jkohen.util.Resources;
 
public class SmileyBox extends Dialog implements ActionListener, KeyListener
{
    private EIRC eirc;
	private Frame f;
 
 
    public SmileyBox(EIRC eirc, Frame f, String title)
    {
		super(f, false);
    	this.eirc = eirc;
		this.f = f;
 
		setFont(eirc.getFont());
 
    	GridBagLayout gb = new GridBagLayout();
    	GridBagConstraints gbc = new GridBagConstraints();
 
    	setLayout(gb);
 
    	gbc.insets = new Insets(1, 1, 1, 1);
 
    	ImageButton b;
 
    	ImageSmiley smiley1;
    	ImageSmiley smiley2;
    	ImageSmiley smiley3;
    	ImageSmiley smiley4;
    	ImageSmiley smiley5;
    	ImageSmiley smiley6;
    	ImageSmiley smiley7;
    	ImageSmiley smiley8;
    	ImageSmiley smiley9;
    	ImageSmiley smiley10;
    	ImageSmiley smiley11;
    	ImageSmiley smiley12;
    	ImageSmiley smiley13;
    	ImageSmiley smiley14;
    	ImageSmiley smiley15;
    	ImageSmiley smiley16;
    	ImageSmiley smiley17;
    	ImageSmiley smiley18;
    	ImageSmiley smiley19;
    	ImageSmiley smiley20;
    	ImageSmiley smiley21;
    	ImageSmiley smiley22;
    	ImageSmiley smiley23;
    	ImageSmiley smiley24;
 
    	smiley1 = new ImageSmiley(Resources.getImage("smiley1"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 0;
		gbc.gridy = 0;
		gb.setConstraints(smiley1, gbc);
    	add(smiley1);
 
    	smiley2 = new ImageSmiley(Resources.getImage("smiley2"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 1;
		gbc.gridy = 0;
		gb.setConstraints(smiley2, gbc);
    	add(smiley2);
 
    	smiley3 = new ImageSmiley(Resources.getImage("smiley3"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 2;
		gbc.gridy = 0;
		gb.setConstraints(smiley3, gbc);
    	add(smiley3);
 
		smiley4 = new ImageSmiley(Resources.getImage("smiley4"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 3;
		gbc.gridy = 0;
		gb.setConstraints(smiley4, gbc);
    	add(smiley4);
 
		smiley5 = new ImageSmiley(Resources.getImage("smiley5"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 4;
		gbc.gridy = 0;
		gb.setConstraints(smiley5, gbc);
    	add(smiley5);
 
    	smiley6 = new ImageSmiley(Resources.getImage("smiley6"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 5;
		gbc.gridy = 0;
		gb.setConstraints(smiley6, gbc);
    	add(smiley6);
 
    	smiley7 = new ImageSmiley(Resources.getImage("smiley7"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 0;
		gbc.gridy = 1;
		gb.setConstraints(smiley7, gbc);
    	add(smiley7);
 
		smiley8 = new ImageSmiley(Resources.getImage("smiley8"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 1;
		gbc.gridy = 1;
		gb.setConstraints(smiley8, gbc);
    	add(smiley8);
 
		smiley9 = new ImageSmiley(Resources.getImage("smiley9"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 2;
		gbc.gridy = 1;
		gb.setConstraints(smiley9, gbc);
    	add(smiley9);
 
		smiley10 = new ImageSmiley(Resources.getImage("smiley10"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 3;
		gbc.gridy = 1;
		gb.setConstraints(smiley10, gbc);
    	add(smiley10);
 
		smiley11 = new ImageSmiley(Resources.getImage("smiley11"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 4;
		gbc.gridy = 1;
		gb.setConstraints(smiley11, gbc);
    	add(smiley11);
 
		smiley12 = new ImageSmiley(Resources.getImage("smiley12"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 5;
		gbc.gridy = 1;
		gb.setConstraints(smiley12, gbc);
    	add(smiley12);
 
		smiley13 = new ImageSmiley(Resources.getImage("smiley13"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 0;
		gbc.gridy = 2;
		gb.setConstraints(smiley13, gbc);
    	add(smiley13);
 
		smiley14 = new ImageSmiley(Resources.getImage("smiley14"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 1;
		gbc.gridy = 2;
		gb.setConstraints(smiley14, gbc);
    	add(smiley14);
 
		smiley15 = new ImageSmiley(Resources.getImage("smiley15"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 2;
		gbc.gridy = 2;
		gb.setConstraints(smiley15, gbc);
    	add(smiley15);
 
		smiley16 = new ImageSmiley(Resources.getImage("smiley16"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 3;
		gbc.gridy = 2;
		gb.setConstraints(smiley16, gbc);
    	add(smiley16);
 
		smiley17 = new ImageSmiley(Resources.getImage("smiley17"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 4;
		gbc.gridy = 2;
		gb.setConstraints(smiley17, gbc);
    	add(smiley17);
 
		smiley18 = new ImageSmiley(Resources.getImage("smiley18"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 5;
		gbc.gridy = 2;
		gb.setConstraints(smiley18, gbc);
    	add(smiley18);
 
		smiley19 = new ImageSmiley(Resources.getImage("smiley19"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 0;
		gbc.gridy = 3;
		gb.setConstraints(smiley19, gbc);
    	add(smiley19);
 
		smiley20 = new ImageSmiley(Resources.getImage("smiley20"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 1;
		gbc.gridy = 3;
		gb.setConstraints(smiley20, gbc);
    	add(smiley20);
 
		smiley21 = new ImageSmiley(Resources.getImage("smiley21"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 2;
		gbc.gridy = 3;
		gb.setConstraints(smiley21, gbc);
    	add(smiley21);
 
		smiley22 = new ImageSmiley(Resources.getImage("smiley22"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 3;
		gbc.gridy = 3;
		gb.setConstraints(smiley22, gbc);
    	add(smiley22);
 
		smiley23 = new ImageSmiley(Resources.getImage("smiley23"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 4;
		gbc.gridy = 3;
		gb.setConstraints(smiley23, gbc);
    	add(smiley23);
 
		smiley24 = new ImageSmiley(Resources.getImage("smiley24"));
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 5;
		gbc.gridy = 3;
		gb.setConstraints(smiley24, gbc);
    	add(smiley24);
 
		gbc.gridy++;
		gbc.gridx = 0;
		gbc.ipady = 4;
 
		b = new ImageButton(Resources.getString("close"));
	    b.setActionCommand("cancel");
	    b.addActionListener(this);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.CENTER;
		gbc.gridwidth = GridBagConstraints.REMAINDER;
	    gb.setConstraints(b, gbc);
		add(b);
 
		addKeyListener(this);
		smiley1.addActionListener(this);
		smiley2.addActionListener(this);
		smiley3.addActionListener(this);
		smiley4.addActionListener(this);
		smiley5.addActionListener(this);
		smiley6.addActionListener(this);
		smiley7.addActionListener(this);
		smiley8.addActionListener(this);
		smiley9.addActionListener(this);
		smiley10.addActionListener(this);
		smiley11.addActionListener(this);
		smiley12.addActionListener(this);
		smiley13.addActionListener(this);
		smiley14.addActionListener(this);
		smiley15.addActionListener(this);
		smiley16.addActionListener(this);
		smiley17.addActionListener(this);
		smiley18.addActionListener(this);
		smiley19.addActionListener(this);
		smiley20.addActionListener(this);
		smiley21.addActionListener(this);
		smiley22.addActionListener(this);
		smiley23.addActionListener(this);
		smiley24.addActionListener(this);
 
		updateBackground(this, getBackground());
 
		pack();
    	setTitle(title);
		setResizable(false);
    	setVisible(true);
    }
 
    public void actionPerformed(ActionEvent ev)
    {
		String action = ev.getActionCommand();
		Object source = ev.getSource();
 
		if (source.equals("smiley1"))
		{
			System.out.println("t");
		}
		if (action.equals("cancel"))
		{
	    	processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
		}
    }
 
	public void keyTyped(KeyEvent ke)
	{
	}
 
	public void keyReleased(KeyEvent ke)
	{
	}
 
	public void keyPressed(KeyEvent ke)
	{
		if (ke.getKeyCode() == KeyEvent.VK_ESCAPE)
	    	processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
	}
 
 
 
 
	public void updateBackground(Container ct, Color cl)
    {
		ct.setBackground(cl);
		Component cp[] = ct.getComponents();
		for (int i = 0; i < cp.length; i++)
		{
			if (cp[i] instanceof Container)
				updateBackground((Container)cp[i], cl);
			else
				if (!(cp[i] instanceof TextField))
					cp[i].setBackground(cl);
		}
    }
 
	@Override
	public void show()
	{
		pack();
    	setLocation((f.getSize().width - getSize().width) / 2 + f.getLocation().x, (f.getSize().height - getSize().height) / 2 + f.getLocation().y);
 
		setBackground(eirc.getBackground());
		setForeground(eirc.getForeground());
		super.show();
	}
}
Merci d'avance pour votre aide.