affichage d'une image avec du swing
Bonjour voila g lu pas mal de truc sur le forum, j'ai essayé pas mal de truc mais impossible d'afficher une image dans mon interface graphique.
Donc si quelqu'un pouvait me filer un aide un peu plus perso sa serait cool.
Voila mon code bon c pas le truc final c juste pour faire des test pour réussir à afficher ce que je veux mais sa marche pas.
Merci de regarder et me dir ce ki cloche.
Code:
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
|
package paqIHM;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class testImg extends javax.swing.JFrame {
private static final long serialVersionUID = -4713672432547856626L;
private JLabel jLabel1;
public static void main(String[] args) {
testImg inst = new testImg();
inst.setVisible(true);
}
public testImg() {
super();
init();
}
private void init() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JPanel pannel = new JPanel();
ImageIcon image = new ImageIcon("images/test.gif");
jLabel1 = new JLabel("salut",image, JLabel.CENTER);
pannel.add(jLabel1);
this.getContentPane().add(pannel);
pack();
} catch (Exception e) {
e.printStackTrace();
}
}
} |