no save
Assistance
Achat
News

Forum | programmation
image dans une JFrame en Java
yotheyoung, le jeu. 30 août 2007 à 14:33:07
Bonjour,

je cherche à afficher une image dans une JFrame en java.
J'utilise Eclipse et Visual Editor.

Voici mon code:

Public class fenetre_image extends JFrame{

private JPanel jContentPane=null;
private JPanel pan;

public fenetre_image(){
super();
this.setContentPane(getJContentPane());
pan = new Panneau();
getContentPane().add(pan);
}
}

public class Panneau extends JPanel{
private Image im = null;

public Panneau(){
im=getToolkit().getImage("mon_image.gif");
}

public void paintComponent(Graphics g){
super.paintComponent(g);
int x=10,y=10;
if (im!=null){
g.drawImage(im,x,y,this);
}
}
}

ma méthode main:
public static void main(){
fenetre_image fi=new fenetre_image();
fi.setVisible(true);
}


la JFrame s'affiche mais le contenu n'affiche pas l'image.

Je suppose que c'est parce que je n'appelle jamais la méthode paintComonent, mais je ne sais pas ou l'apeller et avec quelle parametre de tpe Graphics.

Quelqu'un pourrait m'aider?????

merci d'avance Configuration: Windows XP
Firefox 2.0.0.4


arth
août 07
Suivant
REPONSES
arth
août 07
yotheyoung
août 07
arth
août 07
yotheyoung
août 07
kij_82
août 07
arth
août 07
yotheyoung
août 07
yotheyoung
août 07
kij_82
août 07
asma40
17 avr.
Version Web
Réalisé par RedShift
no save