TP
This commit is contained in:
43
DEV2.1/TDs/Img.java
Normal file
43
DEV2.1/TDs/Img.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Img extends JComponent {
|
||||
private Image img;
|
||||
|
||||
public Img() {
|
||||
// Chargement de l'image
|
||||
img = new ImageIcon("fond.png").getImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (img != null) {
|
||||
g.drawImage(img, 0, 0, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(500, 500); // Ajustez à la taille de l'image
|
||||
}
|
||||
}
|
||||
|
||||
class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setLocation(100, 100);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Img imagePanel = new Img();
|
||||
this.add(imagePanel);
|
||||
|
||||
this.pack(); // Ajuste la fenêtre à la taille du contenu
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(Fenetre::new);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user