début d'un menu dans TestV2
This commit is contained in:
BIN
TestV1/res/fond-ecran.jpg!d
Normal file
BIN
TestV1/res/fond-ecran.jpg!d
Normal file
Binary file not shown.
After Width: | Height: | Size: 421 KiB |
50
TestV1/src/Menu.java
Normal file
50
TestV1/src/Menu.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
public class Menu extends JFrame {
|
||||||
|
|
||||||
|
private Image imageDeFond;
|
||||||
|
|
||||||
|
public Menu() {
|
||||||
|
// Charge l'image de fond
|
||||||
|
try {
|
||||||
|
imageDeFond = ImageIO.read(new File("../res/fond-ecran.jpg!d"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration de la fenêtre
|
||||||
|
setTitle(" Dorfromantik");
|
||||||
|
setSize(800, 600); // Taille de la fenêtre
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
// Ajouter le panneau avec image de fond
|
||||||
|
setContentPane(new PanneauImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Classe interne pour le panneau personnalisé qui dessine l'image en fond
|
||||||
|
class PanneauImage extends JPanel {
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
if (imageDeFond != null) {
|
||||||
|
g.drawImage(imageDeFond, 0, 0, getWidth(), getHeight(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new Menu().setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user