Bonjour,

Je débute avec Swing, j'ai cherché chez mon ami google et la doc...Mais ça marche pas..

Je cherche à disposer dans un JFrame des JPanel contenant une image jpg. Mais je n'arrive pas à les afficher à l'écran..

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package Graphismes;
 
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
/**
 *
 * 
 */
public class LePlateau extends JFrame {
 
    int xx=0;
    int yy=0;
 
    public LePlateau(){
        this.setTitle("Jeu");
 
        this.setSize(800, 600);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
 
        UneCase2 unecase;
 
        for(int i=0,n=12;i<n;i++)
        {
            xx = 7 + Math.round(i%3)*(200 + 10);
            yy = 7 + (int)Math.floor(i/3)*(100 + 10);
            unecase = new UneCase2();
 
        }
 
        this.setVisible(true);
 
    }
 
   class UneCase2 extends JPanel{
 
   @Override public void paintComponent(Graphics g){
        try {
              Image img = ImageIO.read(new File("image/case.jpg"));
              g.drawImage(img, xx, yy, this);
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                   e.printStackTrace();
                }
 
        }
 
}
 
 
 
}

Merci d'avance