Files
linea_app_projet/projet_linea/src/CadreDeConnexion.java

89 lines
3.3 KiB
Java
Raw Normal View History

2026-03-17 15:03:07 +01:00
import java.awt.*;
2026-03-27 14:43:31 +01:00
import java.net.URL;
import javax.imageio.ImageIO;
2026-03-17 15:03:07 +01:00
import javax.swing.*;
public class CadreDeConnexion extends JFrame {
2026-03-27 15:34:53 +01:00
2026-03-17 15:03:07 +01:00
2026-03-27 14:43:31 +01:00
//--------------------------------------------------------------------------
// Méthode peremttant de charger(récupérer) l'image îcone depuis Ressources
// -------------------------------------------------------------------------
private Image chargerImageDepuisRessource(String cheminRessource) {
2026-03-27 15:34:53 +01:00
// Cette méthode doit seulement charger l'image, pas rappeler elle-même.
2026-03-27 14:43:31 +01:00
try {
URL url = getClass().getResource(cheminRessource);
if (url != null) {
return ImageIO.read(url);
}
System.err.println("Ressource introuvable : " + cheminRessource);
} catch (Exception e) {
System.err.println("Erreur chargement image : " + e.getMessage());
}
return null;
}
2026-03-17 15:03:07 +01:00
public CadreDeConnexion() {
2026-03-27 14:43:31 +01:00
// Image de fond de la page de connexion
Background panelBackground = null;
// 1. On change l'icône de CETTE fenêtre (this)
Image imageConnexion = chargerImageDepuisRessource("/images/icone.png");
if (imageConnexion != null) {
2026-03-27 15:34:53 +01:00
// On applique la même image comme icône de la fenêtre
2026-03-27 14:43:31 +01:00
this.setIconImage(imageConnexion);
2026-03-27 15:34:53 +01:00
// On prépare aussi le fond pour le panneau de connexion
2026-03-27 14:43:31 +01:00
panelBackground = new Background(imageConnexion);
}
// 2. Configuration de base
setTitle("ZENITH FLUX");
2026-03-17 15:03:07 +01:00
setSize(800, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null); // Centre la fenêtre
2026-03-27 15:34:53 +01:00
// 2. Style du panneau principal (Gris foncé)
// On utilise ZoneDessin pour pouvoir dessiner l'image en fond
2026-03-27 14:43:31 +01:00
JPanel panel = new ZoneDessin(panelBackground);
panel.setLayout(new GridBagLayout());
2026-03-27 15:34:53 +01:00
setContentPane(panel);
2026-03-17 15:03:07 +01:00
// Conteneur pour les éléments (pour les empiler verticalement)
Box box = Box.createVerticalBox();
2026-03-27 14:43:31 +01:00
// 4. Création des composants
2026-03-17 15:03:07 +01:00
JLabel titre = new JLabel("CONNEXION");
titre.setForeground(Color.WHITE);
titre.setFont(new Font("Arial", Font.BOLD, 24));
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
JTextField userField = new JTextField(15);
userField.setMaximumSize(new Dimension(250, 30));
JPasswordField passField = new JPasswordField(15);
passField.setMaximumSize(new Dimension(250, 30));
JButton loginBtn = BoutonsManager.creerBoutonConnexion(userField, passField, this);
2026-03-17 15:03:07 +01:00
2026-03-27 14:43:31 +01:00
// 5. Ajout des composants avec des espaces (Struts)
2026-03-17 15:03:07 +01:00
box.add(titre);
box.add(Box.createVerticalStrut(30)); // Espace
box.add(new JLabel("<html><font color='white'>Utilisateur :</font></html>"));
box.add(userField);
box.add(Box.createVerticalStrut(15));
box.add(new JLabel("<html><font color='white'>Mot de passe :</font></html>"));
box.add(passField);
box.add(Box.createVerticalStrut(30));
box.add(loginBtn);
box.add(Box.createVerticalStrut(10));
JButton createBtn = BoutonsManager.creerBoutonCreerCompte(this);
2026-03-17 15:03:07 +01:00
box.add(createBtn);
panel.add(box); // Ajoute la boîte au centre du GridBagLayout
setVisible(true);
}
}