Bonjour, svp j'ai un problème au niveau d'animation d'un carré, pour l'affichage il s'affiche bien, mais pour la l'animation et le movement non !
j'ai associé a ce carré une fonction move(); qui incrément sa position X et le dessiner une autre fois, mais je sais pas le problème car l'affichage s'arrete sans aucune condition , svp aidez-moi
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 package Pack_Tr_No1; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JPanel; /** * * @author CY_15 */ public class OG extends JPanel{ private static int id; private final int idOG; private int x; private int y; private int h; private int l; private Color Col; private String Nom; public OG() { idOG=++id; x=0; y=0; h=0; l=0; Col=Color.BLUE; Nom="OG_"+idOG; } public OG( int xx, int yy, int ll, int hh, String nn ) { idOG=++id; x=xx; y=yy; h=hh; l=ll; Nom=nn+idOG; } public OG( int xx, int yy, int ll, int hh) { idOG=++id; x=xx; y=yy; h=hh; l=ll; Nom="OG_"+idOG; } // les Methodes : @Override public void paintComponent(Graphics g) { Graphics2D g1=(Graphics2D) g; super.paintComponent(g1); Color c1= this.getCol(); g1.setColor( c1); g1.fillRect( x, y, h, l); } public void move() { while (true) { this.setX(++x); try { Thread.sleep(3); repaint(); } catch (InterruptedException ex) { System.out.println("Erreur"); } } } //Geters & Seters : //Geters : public int getId() { return this.idOG; } @Override public int getX() { return this.x; } @Override public int getY() { return this.y; } public int getH() { return this.h; } public int getL() { return this.l; } public Color getCol() { return this.Col; } public String getNom() { return this.Nom; } // Setrs : public void setX(int xx) { this.x = xx; } public void setY(int yy) { this.y = yy; } public void setH(int hh) { this.h = hh; } public void setL(int ll) { this.l = ll; } public void setCol(Color cc) { this.Col= cc; } public void setNom(String nn) { this.Nom = nn; } }
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 public class Travail_No1_MOO{ public static void main(String[] args) { JFrame f = new JFrame("OG ..."); f.setSize(600, 500); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); f.setVisible(true); OG og=new OG(); og.setL(50); og.setH(50); og.setCol(Color.CYAN); f.setContentPane(og); og.moveH(); } }
Partager