regroupement bouton dans la classe boutonManager.java

This commit is contained in:
2026-03-26 00:33:46 +01:00
parent fc92f720c3
commit d8b2ef6e49
5 changed files with 182 additions and 90 deletions

View File

@@ -30,11 +30,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);
// 4. Ajout des composants avec des espaces (Struts)
box.add(titre);
@@ -48,91 +44,11 @@ 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
// 5. Logique du bouton
loginBtn.addActionListener(e -> {
String user = userField.getText();
String pass = new String(passField.getPassword());
int userId = GestionBDD.verifierConnexion(user, pass);
if (userId != -1) {
dispose();
Jeu jeu = new Jeu(userId);
jeu.demarrer();
} else {
JOptionPane.showMessageDialog(this, "Acces refuse");
}
});
createBtn.addActionListener(evt -> {
JFrame createFrame = new JFrame("Creation de compte");
createFrame.setSize(800, 600);
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);
Box createBox = Box.createVerticalBox();
JLabel createTitre = new JLabel("CREATION DE COMPTE");
createTitre.setForeground(Color.WHITE);
createTitre.setFont(new Font("Arial", Font.BOLD, 24));
createTitre.setAlignmentX(Component.CENTER_ALIGNMENT);
JTextField newUserField = new JTextField(15);
newUserField.setMaximumSize(new Dimension(250, 30));
JPasswordField newPassField = new JPasswordField(15);
newPassField.setMaximumSize(new Dimension(250, 30));
JButton createAccountBtn = new JButton("Créer");
createAccountBtn.setBackground(new Color(70, 130, 180));
createAccountBtn.setForeground(Color.WHITE);
createAccountBtn.setFocusPainted(false);
createAccountBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
createBox.add(createTitre);
createBox.add(Box.createVerticalStrut(30));
createBox.add(new JLabel("<html><font color='white'>Nouvel utilisateur :</font></html>"));
createBox.add(newUserField);
createBox.add(Box.createVerticalStrut(15));
createBox.add(new JLabel("<html><font color='white'>Mot de passe :</font></html>"));
createBox.add(newPassField);
createBox.add(Box.createVerticalStrut(30));
createBox.add(createAccountBtn);
createPanel.add(createBox);
createAccountBtn.addActionListener(e -> {
String u = newUserField.getText().trim();
String p = new String(newPassField.getPassword());
if (u.isEmpty() || p.isEmpty()) {
JOptionPane.showMessageDialog(createFrame, "Utilisateur et mot de passe requis");
return;
}
boolean ok = GestionBDD.creerUtilisateur(u, p);
if (ok) {
JOptionPane.showMessageDialog(createFrame, "Compte cree avec succes.");
createFrame.dispose();
} else {
JOptionPane.showMessageDialog(createFrame, "Échec : le nom d'utilisateur existe deja ou erreur.");
}
});
createFrame.setVisible(true);
});
setVisible(true);
}
}