Bonjour,

Je veux insérer une image dans un jpanel.

voici le code :

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
 
import java.awt.*;
import javax.swing.*;
 
class fenetre extends JFrame
    {
    private JPanel pan ;
    fenetre (){
        setTitle ("IMAGES") ;
        setSize (300, 300) ;
        pan = new Panneau() ;
        getContentPane().add(pan) ;
    }
}
 
class Panneau extends JPanel
    {
    private Image photo = null;
    public Panneau(){
        photo = getToolkit().getImage("h_9_ill_902074_magadiscio.jpg") ;
    }
 
    public void paintComponent(Graphics g){
        super.paintComponent(g) ;
        if(photo != null){
            g.drawImage (photo, 0, 0, this);System.out.println("photo");}
        }
}
 
public class dns{
    public static void main (String args[]){
        fenetre fen = new fenetre() ;
        fen.setVisible(true) ;
    }
}

Il affiche la fenetre mais il ya rien dedant.
Si qq1 voit où est le probleme, n'hésite pas et merci.