bonjour
le rond déplace pas,
mon prg consiste,que le rond doit déplacer en diagonale et revenir depuis de début ainsi de suite, aidez moi svp,j'ai aucun erreur lors compilation et exécution
après avoir exécuté,il affiche une fenêtre mais il n' y a pas le rond,mais il déplace pas non plus
veuillez m'aidez svp
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 import java.awt.Dimension; import javax.swing.JFrame; public class Fenetre extends JFrame { private Panneau pan=new Panneau(); public Fenetre() { this.setTitle("Animation"); this.setSize(300,300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setContentPane(pan); this.setVisible(true); go(); } private void go() { for(;;) { int x=pan.getPosX(),y=pan.getPosY(); x++; y++; pan.setPosX(x); pan.setPosY(y); pan.repaint(); try { Thread.sleep(10); } catch(InterruptedException e) { e.printStackTrace(); } if(x==pan.getWidth()|| y==pan.getHeight()); { pan.setPosX(-50); pan.setPosY(-50); } } } public static void main(String[]args) { Fenetre pan=new Fenetre(); } } import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Panneau extends JPanel { private int posX=-50; private int posY=-50; public void paintComponent(Graphics g) { g.setColor(Color.white); g.fillRect(0,0,this.getWidth(),this.getHeight()); g.setColor(Color.red); g.fillOval(posX,posY,50,50); } public int getPosX() { return posX; } public void setPosX(int posX) { this.posX=posX; } public int getPosY() { return posY; } public void setPosY(int posY) { this.posY=posY; } }
Partager