Swing

Résolu
cs_limalima Messages postés 124 Date d'inscription dimanche 31 août 2008 Statut Membre Dernière intervention 16 décembre 2010 - 16 oct. 2008 à 00:09
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 - 16 oct. 2008 à 09:00
Bonjour,
j'ai un code pour faire un dessin, mais je ne comprends pas pourquoi il ne fonctionne pas!!
help.merci

import

java.awt.Graphics;
import

java.awt.Image;
import

java.io.File;
import

java.io.IOException;
import

javax.imageio.ImageIO;
import

javax.swing.JPanel;

public

classPanneau
extends JPanel {

public
void paintComponent(Graphics g){

g.fillOval(70, 70, 70, 70);

}

public
static
void main(String [] arg){

new Panneau();

}

}

1 réponse

Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
16 oct. 2008 à 09:00
Salut:

Pour visualiser une application Swing, il faut utiliser un composant lourd:
1. JFrame
2. JDialog
3. JApplet
4. JWindow

public class MyPanel extends JPanel {
    public MyPanel() {
       setPreferredSize(new Dimension(300, 300));
    }

    @Override
    protected void paintComponent(Graphics g) {
       g.drawOval(100, 100, 100, 100);
    }
}

public class MyFrame extends JFrame {
    public MyFrame() {
       super("Dessin");
       setDefaultCloseOperation(EXIT_ON_CLOSE);
       getContentPane().add(new MyPanel());
       pack();
    }

    public static void main(String[] args) {
       MyFrame frame = new MyFrame();
       frame.setVisible(true);
    }
}
3
Rejoignez-nous