From 3d6f93949c9c9d35854b3add333668f1d21b5037 Mon Sep 17 00:00:00 2001 From: sehl Date: Sat, 25 Oct 2025 20:08:22 +0200 Subject: [PATCH] Maj de la fenetre ajout --- src/fr/iutfbleau/papillon/FenetreAjout.java | 112 +++++++------------- 1 file changed, 39 insertions(+), 73 deletions(-) diff --git a/src/fr/iutfbleau/papillon/FenetreAjout.java b/src/fr/iutfbleau/papillon/FenetreAjout.java index b5593e2..9f061e6 100644 --- a/src/fr/iutfbleau/papillon/FenetreAjout.java +++ b/src/fr/iutfbleau/papillon/FenetreAjout.java @@ -2,31 +2,27 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.*; -public class FenetreAjout extends JFrame implements ActionListener { +public class FenetreAjout extends JFrame { private final JTextField champTitre; private final JTextArea champContenu; private Integer[] nombres = {1, 2, 3, 4, 5}; private JComboBox rang = new JComboBox<>(nombres); - - private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Gris"}; + private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Rose"}; private final JComboBox comboTheme = new JComboBox<>(nomsCouleurs); - + private GestionAjout listBtnAjout; - private final JButton boutonValider; - private final JButton boutonAnnuler; - private final Main parent; - public FenetreAjout(Main parent) { super("Ajouter un rappel"); - this.parent = parent; + ImageIcon logo = new ImageIcon("logo.png"); + setIconImage(logo.getImage()); setSize(350, 250); + setAlwaysOnTop(true); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -40,42 +36,60 @@ public class FenetreAjout extends JFrame implements ActionListener { // Titre JLabel lblTitre = new JLabel("Titre :"); - champTitre = new JTextField(20); - c.gridx = 0; c.gridy = 1; c.weightx = 0; + champTitre = new JTextField(50); + champTitre.setDocument(new LimiteContenu(50)); + c.gridx = 0; + c.gridy = 1; + c.weightx = 0; centre.add(lblTitre, c); - c.gridx = 1; c.gridy = 1; c.weightx = 1; + c.gridx = 1; + c.gridy = 1; + c.weightx = 1; centre.add(champTitre, c); // Contenu JLabel lblContenu = new JLabel("Contenu :"); champContenu = new JTextArea(4, 20); + champContenu.setDocument(new LimiteContenu(200)); champContenu.setLineWrap(true); // active le retour à la ligne champContenu.setWrapStyleWord(true); // évite de couper un mot en plein milieu JScrollPane scroll = new JScrollPane(champContenu, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - c.gridx = 0; c.gridy = 2; c.weightx = 0; + c.gridx = 0; + c.gridy = 2; + c.weightx = 0; c.fill = GridBagConstraints.BOTH; centre.add(lblContenu, c); - c.gridx = 1; c.gridy = 2; c.weightx = 1; c.weighty = 1.0; + c.gridx = 1; + c.gridy = 2; + c.weightx = 1.0; + c.weighty = 1.0; centre.add(scroll, c); // Rang JLabel lblrang = new JLabel("Rang :"); - c.gridx = 0; c.gridy = 3; c.weightx = 0; c.weighty = 0.0; + c.gridx = 0; + c.gridy = 3; + c.weightx = 0; + c.weighty = 0.0; centre.add(lblrang, c); - c.gridx = 1; c.gridy = 3; c.weightx = 1; - centre.add(rang, c); - - + c.gridx = 1; + c.gridy = 3; + c.weightx = 1; + centre.add(rang, c); // Theme - c.gridx = 0; c.gridy = 4; c.weightx = 0; + c.gridx = 0; + c.gridy = 4; + c.weightx = 0; centre.add(new JLabel("Theme :"), c); // liste déroulante de couleurs - c.gridx = 1; c.gridy = 4; c.weightx = 1; + c.gridx = 1; + c.gridy = 4; + c.weightx = 1; comboTheme.setRenderer(new CouleurList()); comboTheme.setSelectedItem("Bleu"); // valeur par défaut centre.add(comboTheme, c); @@ -83,14 +97,10 @@ public class FenetreAjout extends JFrame implements ActionListener { // Bas : boutons JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); - boutonValider = new JButton("Valider"); - boutonAnnuler = new JButton("Annuler"); - boutonValider.addActionListener(this); - boutonAnnuler.addActionListener(this); - - bas.add(boutonValider); - bas.add(boutonAnnuler); + listBtnAjout = new GestionAjout(this,parent,champTitre,champContenu,rang,comboTheme); + bas.add(listBtnAjout.get(0)); + bas.add(listBtnAjout.get(1)); add(bas, BorderLayout.SOUTH); } @@ -99,48 +109,4 @@ public class FenetreAjout extends JFrame implements ActionListener { return CouleurList.couleurDe(nom); } - -@Override - public void actionPerformed(ActionEvent e) { - Object src = e.getSource(); - - if (src == boutonAnnuler) { - // revenir à la fenêtre principale - Point pos = this.getLocation(); - - parent.setLocation(pos); - parent.setVisible(true); - this.dispose(); - return; - } - - if (src == boutonValider) { - String titre = champTitre.getText().trim(); - String contenu = champContenu.getText().trim(); - int Nrang = (Integer) rang.getSelectedItem(); - String cTheme = (String)comboTheme.getSelectedItem(); - - - GestionRappel g = new GestionRappel(); - - if (titre.isEmpty() || contenu.isEmpty()) { - JOptionPane.showMessageDialog(this, "Veuillez remplir tout les champs.", "Champs manquants", JOptionPane.WARNING_MESSAGE); - return; - }else{ - - try{ - g.ajouter(new Rappel(titre,contenu,cTheme,Nrang)); - } catch (Exception ex) { - ex.printStackTrace(); // affiche l'erreur dans le terminal - } - - } - - Main reParent = new Main(); - reParent.setLocation(this.getLocation()); - reParent.setVisible(true); - dispose(); - } - } - }