Aidez moi en java

Résolu
bouchrot Messages postés 394 Statut Membre -  
bouchrot Messages postés 394 Statut Membre -
Bonjour,

salut nous avons commencer les interfaces graphiques en java ,donc j'ai fait un programme mais il ne m'affiche rien ,je ne sais pas pourquoi?
voila mon programme

public class Panneau extends JPanel{
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D)g;
GradientPaint gp, gp2, gp3, gp4, gp5, gp6;
gp = new GradientPaint(0, 0, Color.RED, 20, 0, Color.magenta, true);
gp2 = new GradientPaint(20, 0, Color.magenta, 40, 0, Color.blue, true);
gp3 = new GradientPaint(40, 0, Color.blue, 60, 0, Color.green, true);
gp4 = new GradientPaint(60, 0, Color.green, 80, 0, Color.yellow, true);
gp5 = new GradientPaint(80, 0, Color.yellow, 100, 0, Color.orange, true);
gp6 = new GradientPaint(100, 0, Color.orange, 120, 0, Color.red, true);
g2d.setPaint(gp);
g2d.fillRect(0, 0, 20, this.getHeight());
g2d.setPaint(gp2);
g2d.fillRect(20, 0, 20, this.getHeight());
g2d.setPaint(gp3);
g2d.fillRect(40, 0, 20, this.getHeight());
g2d.setPaint(gp4);
g2d.fillRect(60, 0, 20, this.getHeight());
g2d.setPaint(gp5);
g2d.fillRect(80, 0, 20, this.getHeight());
g2d.setPaint(gp6);
g2d.fillRect(100, 0, 40, this.getHeight());
}
public static void main(String[]args)
{
Panneau pan = new Panneau();
}
}

il m'affiche seulement :BUILD SUCCESSFUL

merci

A voir également:

2 réponses

matthoffman Messages postés 499 Statut Membre 47
 
C'est surtout qu'il te faudrait une fenetre, car cree un panneau c'est bien beau mais il faudrait peut etre que tu creer la fenetre avant et apres y integrer ton panneau.

Avec awt, on utilise une Frame

    public static void main(String[]args)
    {
        Panneau pan = new Panneau();
        Frame f = new Frame ();
        
        f.setTitle ("Frame Example");
        f.setSize (300,120);
        f.add(pan);
        f.setVisible(true);

    }
1
bouchrot Messages postés 394 Statut Membre 6
 
oui, c"est régler je te remercie
0
KX Messages postés 19031 Statut Modérateur 3 020
 
Il te faut un setVisible(true) pour que ça fonctionne.
0