Bonjour,
Je voudrais utililiser les Threads pour donner l'impression du mouvement.
Mais je ne sais pas ou mettre ma boucle et ma variable.
D'avance merci de votre aide
le code
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 import java.awt.event.*; import java.awt.*; import javax.swing.*; public class TestGraphic extends JFrame implements Runnable { //static int i; public JPanel test2; Graphics lecontexteGr; public static void main (String[] args) { TestGraphic TG; TG = new TestGraphic(); TG.show(); new Thread(TG).start(); } public TestGraphic () { setSize (300,200); addWindowListener (new WindowAdapter() { public void windowClosing (WindowEvent événement) { System.exit(0); } }); test2 = new lePanneau(); getContentPane().add(test2); } public void run() { int j=0; while (j<100) { j++; repaint(); //sleep(200); } } } class lePanneau extends JPanel { static int i; public void paintComponent (Graphics surface) { i=0; //while (i<1000) { super.paintComponent(surface); surface.drawRect(5, 5, 10, 10); surface.drawArc(20, i,200, 200, 10, 30); i++; } } }
Partager