update mode TRiche by ISmael
This commit is contained in:
@@ -4,11 +4,13 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
|
||||
public class CadreDeConnexion extends JFrame {
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Méthode peremttant de charger(récupérer) l'image îcone depuis Ressources
|
||||
// -------------------------------------------------------------------------
|
||||
private Image chargerImageDepuisRessource(String cheminRessource) {
|
||||
// Cette méthode doit seulement charger l'image, pas rappeler elle-même.
|
||||
try {
|
||||
URL url = getClass().getResource(cheminRessource);
|
||||
if (url != null) {
|
||||
@@ -28,10 +30,10 @@ public class CadreDeConnexion extends JFrame {
|
||||
|
||||
// 1. On change l'icône de CETTE fenêtre (this)
|
||||
Image imageConnexion = chargerImageDepuisRessource("/images/icone.png");
|
||||
// Si l'image est différent de null, on modifie l'icone de notre application
|
||||
// Et on l'applique comme image de fond
|
||||
if (imageConnexion != null) {
|
||||
// On applique la même image comme icône de la fenêtre
|
||||
this.setIconImage(imageConnexion);
|
||||
// On prépare aussi le fond pour le panneau de connexion
|
||||
panelBackground = new Background(imageConnexion);
|
||||
}
|
||||
|
||||
@@ -41,10 +43,11 @@ public class CadreDeConnexion extends JFrame {
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setLocationRelativeTo(null); // Centre la fenêtre
|
||||
|
||||
// 3. Style du panneau principal (Gris foncé)
|
||||
// JPanel panel = new JPanel(new GridBagLayout());
|
||||
// 2. Style du panneau principal (Gris foncé)
|
||||
// On utilise ZoneDessin pour pouvoir dessiner l'image en fond
|
||||
JPanel panel = new ZoneDessin(panelBackground);
|
||||
panel.setLayout(new GridBagLayout());
|
||||
setContentPane(panel);
|
||||
|
||||
// Conteneur pour les éléments (pour les empiler verticalement)
|
||||
Box box = Box.createVerticalBox();
|
||||
@@ -61,11 +64,7 @@ public class CadreDeConnexion extends JFrame {
|
||||
JPasswordField passField = new JPasswordField(15);
|
||||
passField.setMaximumSize(new Dimension(250, 30));
|
||||
|
||||
JButton loginBtn = new JButton("Entrer");
|
||||
loginBtn.setBackground(new Color(70, 130, 180)); // Bleu acier
|
||||
loginBtn.setForeground(Color.WHITE);
|
||||
loginBtn.setFocusPainted(false);
|
||||
loginBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
JButton loginBtn = BoutonsManager.creerBoutonConnexion(userField, passField, this);
|
||||
|
||||
// 5. Ajout des composants avec des espaces (Struts)
|
||||
box.add(titre);
|
||||
@@ -79,17 +78,12 @@ public class CadreDeConnexion extends JFrame {
|
||||
box.add(loginBtn);
|
||||
box.add(Box.createVerticalStrut(10));
|
||||
|
||||
JButton createBtn = new JButton("Créer un compte");
|
||||
createBtn.setBackground(new Color(70, 130, 180));
|
||||
createBtn.setForeground(Color.WHITE);
|
||||
createBtn.setFocusPainted(false);
|
||||
createBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
JButton createBtn = BoutonsManager.creerBoutonCreerCompte(this);
|
||||
box.add(createBtn);
|
||||
|
||||
panel.add(box); // Ajoute la boîte au centre du GridBagLayout
|
||||
setContentPane(panel); // Branche enfin le panneau personnalisé à la fenêtre
|
||||
|
||||
// 6. Logique du bouton
|
||||
// 5. Logique du bouton
|
||||
loginBtn.addActionListener(e -> {
|
||||
String user = userField.getText();
|
||||
String pass = new String(passField.getPassword());
|
||||
@@ -110,14 +104,17 @@ public class CadreDeConnexion extends JFrame {
|
||||
createFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
createFrame.setLocationRelativeTo(null);
|
||||
|
||||
// On recharge la même image pour la fenêtre de création de compte
|
||||
// afin de lui donner à la fois l'icône et le fond d'écran.
|
||||
Background panelBackgroundCreation = null;
|
||||
Image imageCreation = chargerImageDepuisRessource("/images/icone.png");
|
||||
if (imageCreation != null) {
|
||||
createFrame.setIconImage(imageCreation);
|
||||
panelBackgroundCreation = new Background(imageCreation);
|
||||
}
|
||||
Background panelBackgroundCreation = (imageCreation != null) ? new Background(imageCreation) : null;
|
||||
|
||||
// Même principe que pour la page de connexion : le fond est dessiné par ZoneDessin
|
||||
JPanel createPanel = new ZoneDessin(panelBackgroundCreation);
|
||||
// JPanel createPanel = new JPanel(new GridBagLayout());
|
||||
createPanel.setLayout(new GridBagLayout());
|
||||
createFrame.setContentPane(createPanel);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user