Bonjour,

J'ai un problème avec cette ardoise que j'essaie de faire.

Lorsque je fais un repaint(), il y a ce petit bug d'affichage. Si j'ajoute la methode super.paintComponent(g), je n'ai plus l'effet voulu. Même si j'ai vu une solution pour contourner le problème (enregistrement de tous les points et on redessine tous les points à chaque fois) , je ne comprend ce comportement.

Quelqu'un pourrait m'expliquer ?

Nom : Capture.PNG
Affichages : 188
Taille : 4,5 KoNom : Capture2.PNG
Affichages : 187
Taille : 7,8 Ko
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
 
package apj.p3.ardoise;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
 
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
 
public class Ardoise extends JFrame{
 
 
	private static final long serialVersionUID = 1L;
 
	private DessinPan dessinPan;
 
	Ardoise() {
		super("Mon ardoise");
		this.setSize(600,400);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
 
		JPanel pan = (JPanel) this.getContentPane();
		this.setJMenuBar(createMenuBar());
		pan.add(createToolBar(), BorderLayout.NORTH);
		dessinPan = new DessinPan();
		dessinPan.addMouseListener(new MouseAdapter() {
 
			@Override
			public void mousePressed(MouseEvent e) {
				if(e.isPopupTrigger()) {
					createPopMenu().show(e.getComponent(), e.getX() , e.getY());
					System.out.println("popu");
				}			
			}
 
			@Override
			public void mouseReleased(MouseEvent e) {
				if(e.isPopupTrigger()) {
					createPopMenu().show(e.getComponent(), e.getX() , e.getY());
					System.out.println("popu");
				}			
			}
 
		});
		pan.add(dessinPan, BorderLayout.CENTER);
		this.setVisible(true);
	}
 
	private JMenuBar createMenuBar() {
		JMenuBar menuBar = new JMenuBar();
 
		JMenu menuFichier = new JMenu("Fichier");
		menuFichier.setMnemonic('F');
		menuBar.add(menuFichier);
 
		menuFichier.add(actEffacer());
 
		menuFichier.addSeparator();
 
 
		menuFichier.add(actQuitter());
 
 
		JMenu menuEdition= new JMenu("Edition");
		menuEdition.setMnemonic('E');
		menuBar.add(menuEdition);
 
		JMenu mnEForme = new JMenu("Forme du Pointeur");
		mnEForme.setMnemonic('F');
		menuEdition.add(mnEForme);
 
 
		mnEForme.add(actRond());
 
		mnEForme.add(actCarre());
 
 
		menuEdition.addSeparator();
 
		JMenu mnECouleur = new JMenu("Couleur du pointeur");
		mnECouleur.setMnemonic('C');
		menuEdition.add(mnECouleur);
 
 
		mnECouleur.add(actRouge());
 
		mnECouleur.add(actBleu());
 
		mnECouleur.add(actJaune());
 
 
 
 
		return menuBar;
	}
 
	private JToolBar createToolBar() {
		JToolBar toolBar = new JToolBar();
 
		toolBar.add(actCarre());
 
		toolBar.add(actRond());
 
		toolBar.addSeparator();
 
		toolBar.add(actRouge());
 
		toolBar.add(actJaune());
 
		toolBar.add(actBleu());
 
		return toolBar;
	}
 
	private JPopupMenu createPopMenu() {
		JPopupMenu popupMenu = new JPopupMenu();
		popupMenu.add(actEffacer());
		popupMenu.addSeparator();
		popupMenu.add(actRond());
		popupMenu.add(actCarre());
		popupMenu.add(actRouge());
		popupMenu.add(actBleu());
		popupMenu.add(actJaune());
		return popupMenu;
 
	}
 
	 private AbstractAction actEffacer() {
		return new AbstractAction("Effacer") {
 
			private static final long serialVersionUID = 1L;
 
			{
				putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK));
				putValue(MNEMONIC_KEY, KeyEvent.VK_E);
				putValue(SHORT_DESCRIPTION, "Effacer CTRL + E");
			}
 
 
			@Override
			public void actionPerformed(ActionEvent e) {
 
			}
		};
 
	}
 
	private AbstractAction actQuitter() {
		return new AbstractAction("Quitter") {
 
			private static final long serialVersionUID = 1L;
 
			{
 
				putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK));
				putValue(MNEMONIC_KEY, KeyEvent.VK_K);
				putValue(SHORT_DESCRIPTION, "Quitter CTRL + Q");
			}
 
 
			@Override
			public void actionPerformed(ActionEvent e) {
 
			}
		};
 
	}
 
	private AbstractAction actCarre() {
		return new AbstractAction("Carre", new ImageIcon("icons/carre_noir.png")) {
 
			private static final long serialVersionUID = 1L;
 
			{
				putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK));
				putValue(MNEMONIC_KEY, KeyEvent.VK_C);
				putValue(SHORT_DESCRIPTION, "Forme carré CTRL + C");
			}
 
 
			@Override
			public void actionPerformed(ActionEvent e) {
 
			}
		};
 
	}
 
	private AbstractAction actRond() {
		return new AbstractAction("Rond", new ImageIcon("icons/rond_noir.png")) {
 
			private static final long serialVersionUID = 1L;
 
			{
				putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK));
				putValue(MNEMONIC_KEY, KeyEvent.VK_R);
				putValue(SHORT_DESCRIPTION, "Forme rond CTRL + R");
			}
 
 
			@Override
			public void actionPerformed(ActionEvent e) {
 
			}
		};
 
	}
 
	private AbstractAction actRouge() {
		return new AbstractAction("Rouge", new ImageIcon("icons/rouge.png")) {
 
			private static final long serialVersionUID = 1L;
 
			{
				putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK));
				putValue(MNEMONIC_KEY, KeyEvent.VK_R);
				putValue(SHORT_DESCRIPTION, "Couleur rouge CTRL + O");
			}
 
 
			@Override
			public void actionPerformed(ActionEvent e) {
 
			}
		};
 
	}
 
	private AbstractAction actBleu() {
		return new AbstractAction("Bleu", new ImageIcon("icons/bleu.png")) {
 
			private static final long serialVersionUID = 1L;
 
			{
				putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK));
				putValue(MNEMONIC_KEY, KeyEvent.VK_B);
				putValue(SHORT_DESCRIPTION, "Couleur bleu CTRL + B");
			}
 
 
			@Override
			public void actionPerformed(ActionEvent e) {
 
			}
		};
 
	}
 
	private AbstractAction actJaune() {
		return new AbstractAction("Bleu", new ImageIcon("icons/jaune.png")) {
 
			private static final long serialVersionUID = 1L;
 
			{
				putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_J, KeyEvent.CTRL_DOWN_MASK));
				putValue(MNEMONIC_KEY, KeyEvent.VK_J);
				putValue(SHORT_DESCRIPTION, "Couleur jaune CTRL + J");
			}
 
 
			@Override
			public void actionPerformed(ActionEvent e) {
 
			}
		};
 
	}
 
 
 
}
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
 
package apj.p3.ardoise;
 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
 
import javax.swing.JButton;
import javax.swing.JPanel;
 
public class DessinPan extends JPanel{
 
	private static final long serialVersionUID = 1L;
 
	int x = -15;
	int y = -15;
 
	DessinPan () {
 
		this.addMouseMotionListener(new MouseMotionListener() {
 
 
			public void mouseMoved(MouseEvent e) {
				// TODO Auto-generated method stub
 
			}
 
 
			public void mouseDragged(MouseEvent e) {
				x = e.getX();
				y = e.getY();
				repaint();
 
 
			}
		}); 
 
	}
 
	public void paintComponent(Graphics g) {
 
 
 
		g.setColor(Color.black);
		g.fillOval(x, y, 12, 12);
 
 
	}
 
 
}