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
| // appeler ce fichier Test.java
import javax.swing.*;
import java.awt.*;
class PanneauImage extends JPanel {
private static final String IMAGE_FILE = "C:\\...\\DSC03542.JPG";
boolean dimensionAutomatique = true;
private Image imageFond = new ImageIcon(IMAGE_FILE).getImage();
public void paintComponent(Graphics fond) {
super.paintComponent(fond);
if (dimensionAutomatique) {
fond.drawImage(imageFond, 0, 0, getWidth(), getHeight(),this);System.out.print("amel");} else {
fond.drawImage(imageFond, 0, 0, imageFond.getWidth(null), imageFond.getHeight(null), this);System.out.print("samia");}
}
}
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.getContentPane().add(new PanneauImage());
frame.setVisible(true);
}
} |
Partager