Bonjour, j'ai un problème avec mon animation: elle devrait changer la couleur d'un rectangle en faisant varier les couleurs d'un rectangle du bleu au rouge mais quand je lance le programme l'image est directement rouge et je ne vois pas les étapes... Quelqu'un saurait où j'ai fait une erreur svp?
Voici mon code qui lance la fenêtre
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
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.*;
 
public class Fenetre extends JFrame implements ListSelectionListener{
    //Appel de la classe dessin
    Dessin des= new Dessin();
    boolean start=false;
	public Fenetre(){
	setTitle("Von Karman Turbulence");
	setSize (400,350);
	Container contenu=getContentPane();
	bHor= Box.createHorizontalBox();
	contenu.add(bHor);
	//Panneau d'affichage
	panneau=new JPanel();
	//panneau.setBackground(Color.BLUE);
	contenu.add(panneau);
	// Dessin du cercle
	panneau.setLayout(new BorderLayout());
	panneau.add(des, BorderLayout.CENTER);
 
	//Panneau de communication
	panCom= new JPanel();
	panCom.setPreferredSize(new Dimension(300,100));
	contenu.add(panCom,"South");
	   //Bouton pour PanCom
	Bouton1=new JButton("Start");
	Bouton2=new JButton("Stop");
	bHor.add(Bouton1);
	bHor.add(Bouton2);
	EcouteBouton1 ecout1 =new EcouteBouton1();
	EcouteBouton2 ecout2 =new EcouteBouton2();
	Bouton1.addActionListener(ecout1);
	Bouton2.addActionListener(ecout2);
	panCom.add(Bouton1);
	panCom.add(Bouton2);
	   //liste pour panCom
	liste = new JList (reynolds);
	liste.addListSelectionListener(this);
	titre = new JLabel("     Nombre de Reynolds :   ");
	panCom.add(titre);
	panCom.add(liste);
 
	this.setVisible(true);
	go();
	}
 
	public void valueChanged (ListSelectionEvent e)
	{if (!e.getValueIsAdjusting())
	{System.out.println ("Reynolds sélec");
	Object[] valeurs=liste.getSelectedValues();
	for (int i =0; i<valeurs.length; i++)
		System.out.println( (String) valeurs[i]);
	}
	}
	private Box bHor;
	private JButton Bouton1, Bouton2;
	private JPanel panCom, panneau;
	private String[] reynolds = {"20","50","200"};
	private JList liste;
	private JLabel titre;
 
	//bouton start et stop (non programé)
	class EcouteBouton1 implements ActionListener
	{public void actionPerformed (ActionEvent ev)
	{
		 start = true;
	}	
	}
	class EcouteBouton2 implements ActionListener
	{public void actionPerformed (ActionEvent ev)
	{
		System.out.println("Stop");
	}	
	}
	//*****animations*****
	private void go(){
		//========================
        int r1 = des.getR1();
        int b1 = des.getB1();
        //Pour cet exemple, j'utilise une boucle while
        //Vous verrez qu'elle fonctionne très bien
        int m=0;
       while(m<=10){
          r1=25*m;
          b1=250-25*m;
          des.setR1(r1);
          des.setB1(b1);
		//On redessine notre Panneau
        des.repaint();
        m++;
 
       //Pause
       try {
               Thread.sleep(3);
       } catch (InterruptedException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
       }
       }
}
}
Et celui qui dessine les rectangle et le cercle:
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
	import javax.swing.*;
	import java.awt.*;
 
 
 
class Dessin extends JPanel {
	private int r1= 0;
	private int r2= 0;
	private int r3= 0;
	private int r4= 0;
	private int r5= 0;
	private int r6= 0;
	private int b1 = 250;
	private int b2 = 250;
	private int b3 = 250;
	private int b4 = 250;
	private int b5 = 250;
	private int b6 = 250;
 
 
	//getters et setters
	public int getR1() {
		return r1;
	}
	public void setR1(int r1) {
		this.r1 = r1;
	}
	public int getR2() {
		return r2;
	}
	public void setR2(int r2) {
		this.r2 = r2;
	}
	public int getR3() {
		return r3;
	}
	public void setR3(int r3) {
		this.r3 = r3;
	}
	public int getR4() {
		return r4;
	}
	public void setR4(int r4) {
		this.r4 = r4;
	}
	public int getR5() {
		return r5;
	}
	public void setR5(int r5) {
		this.r5 = r5;
	}
	public int getR6() {
		return r6;
	}
	public void setR6(int r6) {
		this.r6 = r6;
	}
	public int getB1() {
		return b1;
	}
	public void setB1(int b1) {
		this.b1 = b1;
	}
	public int getB2() {
		return b2;
	}
	public void setB2(int b2) {
		this.b2 = b2;
	}
	public int getB3() {
		return b3;
	}
	public void setB3(int b3) {
		this.b3 = b3;
	}
	public int getB4() {
		return b4;
	}
	public void setB4(int b4) {
		this.b4 = b4;
	}
	public int getB5() {
		return b5;
	}
	public void setB5(int b5) {
		this.b5 = b5;
	}
	public int getB6() {
		return b6;
	}
	public void setB6(int b6) {
		this.b6 = b6;
	}
	public void paintComponent(Graphics g)
	{ Graphics2D g2d = (Graphics2D)g;
		super.paintComponent(g);
 
 
		Color c = g.getColor();
		//rectangle 1
		g2d.setColor(new Color(r1, 0, b1));
		g2d.fillRect(0,0,50,200);
		//rectangle 2 et 3
		g2d.setColor(new Color(r1, 0, b1));
		g2d.fillRect(50,0,50,50);
		g2d.setColor(new Color(r1, 0, b1));
		g2d.fillRect(50,150,50,50);
		//rectangle 3 et 4
		g2d.setColor(new Color(r1, 0, b1));
		g2d.fillRect(50,50,25,100);
		g2d.setColor(new Color(r1, 0, b1));
		g2d.fillRect(75,50,25,100);
		//rectangle 5 et 6
		g2d.setColor(new Color(r1, 0, b1));
		g2d.fillRect(100,0,300,50);
		g2d.setColor(new Color(r1, 0, b1));
		g2d.fillRect(100,150,300,50);
		//rectangle7 et plus
		int i;
		int j;
		int m=7;
		for(i=100;i<=390;)
			{for(j=50;j<=140;)
			{
		g2d.setColor(new Color(250, 0, 0));
		g2d.fillRect(i,j,10,10);
		j=j+10;
		m=m+1;
			}
			i=i+10;
	        }
		//cylindre
		g.setColor(Color.yellow);
		g.fillOval(50,75,50,50);
		g.setColor(c);
 
	}
 
}
Merci d'avance