bonjour
j’écris le prg suivant,en l’exécutant le fenêtre apparait, mais il n' y rien dedans;
aucune erreur non plus
aidez moi 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
87
88 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() { int x=pan.getPosX(),y=pan.getPosY(); boolean backX=false; boolean backY=false; while(true) { if(x<1)backX=false; if(x>pan.getWidth()-50)backX=true; if(y<1)backY=false; if(y>pan.getHeight()-50)backY=true; if(!backX) pan.setPosX(++x); else pan.setPosX(--x); if(!backY) pan.setPosX(++y); else pan.setPosX(--y); pan.repaint(); try { Thread.sleep(3); } catch(InterruptedException e) { e.printStackTrace(); } } } 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);//on redéfinit une couleur pour notre rond 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