salut à tous, je suis débutante en java, bon voilà je dois concevoir un feu tri-color(rouge, orange,vert) g d'abord définie la classe lampe:
Code java : 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
 
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
 
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JComponent;
import javax.swing.JFrame;
 
 
public class Lampe extends JPanel{
  //attribut
 
     int a,b,c,d;
    Color cc;
 
 
   Lampe(Color cc,int a,int b,int c,int d){
     //constructeur
    this.cc=cc;
    this.a=a;
    this.b=b;
    this.c=c;
    this.d=d;
    }
 
 
    //lampe rouge allume
       public void allumerRouge(){
          cc=Color.RED;
       }
 
      //lampe verte allume
       public void allumerVert(){
           cc=Color.GREEN;
       }
 
      //lampe orange allume
       public void allumerOrange(){
           cc=Color.ORANGE;
        }
 
       //lampe eteinte
       public void eteindreRouge(){
           cc=new Color(100,0,0);
 
      }
      public void eteindreVert(){
           cc=new Color(10,80,10);
 
      }
         public void eteindreOrange(){
           cc=new Color(200,120,50);
 
      }
}
puis g définie la classe FeuTricolor qui va avoir les trois lampes (rouge, vert, orange) comme attribut
Code java : 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
 
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
 
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JComponent;
import javax.swing.JFrame;
 
 
 
public class FeuTricolor extends JPanel{
    //attribut
    Lampe L1,L2,L3;
    int a,b,c,d;
 
 
 
     //le dessin du feu tricolor
 
   public void paint(Graphics G){
 
 
       G.setColor(Color.BLACK);
 
          //dessin du rectangle noir
        G.fillRect(a,b,c,d);
        // dessin de la lampe L1:
        // definir couleur de L1
        G.setColor(L1.cc);
       //definir le cercle (la lampe)
 
        G.fillOval(L1.a,L1.b,L1.c,L1.d);
        G.setColor(L2.cc);
        G.fillOval(L2.a,L2.b,L2.c,L2.d); 
        G.setColor(L3.cc);
        G.fillOval(L3.a,L3.b,L3.c,L3.d);
        G.setColor(L3.cc);
 
 
    }
 
    //constructeur
       FeuTricolor(int a, int b,int c,int d){
           this.a=a;
           this.b=b;
           this.c=c;
           this.d=d;
           Lampe L1=new Lampe (Color.RED,a+10,b+20,c-20,c-20);
           Lampe L2=new Lampe (Color.ORANGE,a+10,b+80,c-20,c-20);
        Lampe L3=new Lampe (Color.GREEN,a+10,b+140,c-20,c-20);
 
       }
 
 
 
          public static void showOnFrame(JComponent component, String frameName) {
        JFrame frame = new JFrame(frameName);
        WindowAdapter wa = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        };
        frame.addWindowListener(wa);
        frame.getContentPane().add(component);
        frame.pack();
        frame.setVisible(true);
        }
 
}

mon problème c l'execution je n'arrive pas à afficher mon feu, je me demande si la methode paint(Graphics G) est correcte ou pas
merci de me répondre , j'espère recevoir vos réponses très vite @+