add icon and app name
This commit is contained in:
@@ -1,24 +1,55 @@
|
||||
import java.awt.*;
|
||||
import java.net.URL;
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
public CadreDeConnexion() {
|
||||
// 1. Configuration de base
|
||||
setTitle("Connexion Linea");
|
||||
|
||||
// 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");
|
||||
// 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) {
|
||||
this.setIconImage(imageConnexion);
|
||||
panelBackground = new Background(imageConnexion);
|
||||
}
|
||||
|
||||
// 2. Configuration de base
|
||||
setTitle("ZENITH FLUX");
|
||||
setSize(800, 600);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setLocationRelativeTo(null); // Centre la fenêtre
|
||||
|
||||
// 2. Style du panneau principal (Gris foncé)
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
panel.setBackground(new Color(30, 30, 30));
|
||||
add(panel);
|
||||
// 3. Style du panneau principal (Gris foncé)
|
||||
// JPanel panel = new JPanel(new GridBagLayout());
|
||||
JPanel panel = new ZoneDessin(panelBackground);
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
// Conteneur pour les éléments (pour les empiler verticalement)
|
||||
Box box = Box.createVerticalBox();
|
||||
|
||||
// 3. Création des composants
|
||||
// 4. Création des composants
|
||||
JLabel titre = new JLabel("CONNEXION");
|
||||
titre.setForeground(Color.WHITE);
|
||||
titre.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
@@ -36,7 +67,7 @@ public class CadreDeConnexion extends JFrame {
|
||||
loginBtn.setFocusPainted(false);
|
||||
loginBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
|
||||
// 4. Ajout des composants avec des espaces (Struts)
|
||||
// 5. Ajout des composants avec des espaces (Struts)
|
||||
box.add(titre);
|
||||
box.add(Box.createVerticalStrut(30)); // Espace
|
||||
box.add(new JLabel("<html><font color='white'>Utilisateur :</font></html>"));
|
||||
@@ -56,8 +87,9 @@ public class CadreDeConnexion extends JFrame {
|
||||
box.add(createBtn);
|
||||
|
||||
panel.add(box); // Ajoute la boîte au centre du GridBagLayout
|
||||
setContentPane(panel); // Branche enfin le panneau personnalisé à la fenêtre
|
||||
|
||||
// 5. Logique du bouton
|
||||
// 6. Logique du bouton
|
||||
loginBtn.addActionListener(e -> {
|
||||
String user = userField.getText();
|
||||
String pass = new String(passField.getPassword());
|
||||
@@ -78,9 +110,16 @@ public class CadreDeConnexion extends JFrame {
|
||||
createFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
createFrame.setLocationRelativeTo(null);
|
||||
|
||||
JPanel createPanel = new JPanel(new GridBagLayout());
|
||||
createPanel.setBackground(new Color(30, 30, 30));
|
||||
createFrame.add(createPanel);
|
||||
Image imageCreation = chargerImageDepuisRessource("/images/icone.png");
|
||||
if (imageCreation != null) {
|
||||
createFrame.setIconImage(imageCreation);
|
||||
}
|
||||
Background panelBackgroundCreation = (imageCreation != null) ? new Background(imageCreation) : null;
|
||||
|
||||
JPanel createPanel = new ZoneDessin(panelBackgroundCreation);
|
||||
// JPanel createPanel = new JPanel(new GridBagLayout());
|
||||
createPanel.setLayout(new GridBagLayout());
|
||||
createFrame.setContentPane(createPanel);
|
||||
|
||||
Box createBox = Box.createVerticalBox();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user