Bonjour,

Introduction:
J'ai vu sur internet que ce sujet était abordé de nobmreuse fois mais AUCUN ne correspondaient à mon sujet précis.

Présentation:
Alors voila je souhaite créer une classe (ici nommée "image.java") qui contiendra une méthode me permettant d'afficher des images à l'endroit ou je veux.(Pour dans le futur l'utiliser pour un jeux mais ce n'est pas vraiment important mtn.)

Problème:
Mon code ne compile apparement sans erreur mais mon image ne s'affiche pas.Pourquoi?

Code:

Voici ma classe "Main.java"
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
package imageTest;
 
import java.awt.Dimension;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
 
public class Main extends JPanel {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
		JFrame fenPrincipale=new JFrame("-ProjetNfa032-");//On definit la JFrame //fen=fenetre
        fenPrincipale.setSize(new Dimension(750,500));
        fenPrincipale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        Image imgTest= new Image();
        imgTest.adresseImg="C:\\Users\\antoine\\Desktop\\imgGalaxy.jpg";
        JPanel panImgTest = null;
        imgTest.fctAfficherImg(panImgTest, 0, 0);
 
        fenPrincipale.setVisible(true);
 
	}
 
}
Et voici ma classe "Image.java"
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
package imageTest;
 
import java.io.IOException;
 
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
 
public class Image extends JPanel{
 
	String adresseImg;
 
	public JPanel fctAfficherImg(JPanel pan ,int posX ,int posY){
		pan=new JPanel();//
		Icon imgIcon=new ImageIcon(adresseImg);
 
		JLabel imgJLabel = new JLabel ();//
		imgJLabel.setIcon(imgIcon);
 
		pan.setLayout(null);//positionement-mise en forme du JPanel
		try {
			pan.setBounds(posX,posY,ImageUtil.getImageHeight(adresseImg),ImageUtil.getImageWidth(adresseImg));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
		pan.add(imgJLabel);
 
		return pan;
	}
 
}
D'avance merci de votre aide la je suis vraiment bloqué.

EDIT1eut etre ceci vient il de ma volonté de placer "en position absolu" mon JPanel?Mais j'en ai ABSOLUMEN BESOIN ! pour la suite.