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
|
package ihm;
import javax.swing.*;
import java.awt.*;
public class imagePanel extends JPanel{
private ImageIcon image;
private int hauteur;
private int largeur;
public imagePanel(){
this.image = new ImageIcon("C:/Program Files/Eclipse SDK/workspace/DBN - De Bonaparte à Napoleon/ihm/terrain.jpg");
this.hauteur = this.image.getIconHeight();
System.out.println(this.hauteur);
this.largeur = this.image.getIconWidth();
System.out.println(this.largeur);
this.setBounds(0,0,this.largeur,this.hauteur);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Image img = this.image.getImage();
g.drawImage(img, 10, 10, null);
}
public static void main(String[] args) {
JFrame fenetre = new JFrame("essai image");
fenetre.setBounds(0,0,800,600);
fenetre.setLayout(null);
imagePanel image = new imagePanel();
image.setVisible(true);
fenetre.add(image);
fenetre.setVisible(true);
}
} |
Partager