Actualiser src/fr/iutfbleau/papillon/FenetreAjout.java

This commit is contained in:
2025-10-21 16:51:03 +02:00
parent 95e8ef3171
commit 07525b46dc
+105 -99
View File
@@ -1,99 +1,105 @@
// package fr.iutfbleau.papillon; // package fr.iutfbleau.papillon;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
public class FenetreAjout extends JFrame implements ActionListener { public class FenetreAjout extends JFrame implements ActionListener {
private final JTextField champTitre; private final JTextField champTitre;
private final JTextArea champContenu; private final JTextArea champContenu;
private final JButton boutonValider; private final JButton boutonValider;
private final JButton boutonAnnuler; private final JButton boutonAnnuler;
private final Main parent;
public FenetreAjout() {
super("Ajouter un rappel"); public FenetreAjout(Main parent) {
super("Ajouter un rappel");
setSize(300, 200); this.parent = parent;
setResizable(false);
setLocationRelativeTo(null); setSize(350, 250);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setResizable(false);
// Layout principal setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new BorderLayout(10, 10));
JPanel centre = new JPanel(new GridBagLayout()); // Layout principal
GridBagConstraints c = new GridBagConstraints(); setLayout(new BorderLayout(10, 10));
c.insets = new Insets(4, 4, 4, 4); JPanel centre = new JPanel(new GridBagLayout());
c.fill = GridBagConstraints.HORIZONTAL; GridBagConstraints c = new GridBagConstraints();
add(centre, BorderLayout.CENTER); c.insets = new Insets(4, 4, 4, 4);
c.fill = GridBagConstraints.HORIZONTAL;
// Titre add(centre, BorderLayout.CENTER);
JLabel lblTitre = new JLabel("Titre :");
champTitre = new JTextField(20); // Titre
c.gridx = 0; JLabel lblTitre = new JLabel("Titre :");
c.gridy = 0; champTitre = new JTextField(20);
c.weightx = 0; c.gridx = 0;
centre.add(lblTitre, c); c.gridy = 0;
c.gridx = 1; c.weightx = 0;
c.gridy = 0; centre.add(lblTitre, c);
c.weightx = 1; c.gridx = 1;
centre.add(champTitre, c); c.gridy = 0;
c.weightx = 1;
// Contenu centre.add(champTitre, c);
JLabel lblContenu = new JLabel("Contenu :");
champContenu = new JTextArea(4, 20); // Contenu
JScrollPane scroll = new JScrollPane(champContenu, JLabel lblContenu = new JLabel("Contenu :");
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, champContenu = new JTextArea(4, 20);
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane scroll = new JScrollPane(champContenu,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
c.gridx = 0; JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
c.gridy = 1;
c.weightx = 0; c.gridx = 0;
c.fill = GridBagConstraints.BOTH; c.gridy = 1;
centre.add(lblContenu, c); c.weightx = 0;
c.gridx = 1; c.fill = GridBagConstraints.BOTH;
c.gridy = 1; centre.add(lblContenu, c);
c.weightx = 1; c.gridx = 1;
centre.add(scroll, c); c.gridy = 1;
c.weightx = 1;
// Bas : boutons centre.add(scroll, c);
JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
boutonValider = new JButton("Valider"); // Bas : boutons
boutonAnnuler = new JButton("Annuler"); JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
boutonValider = new JButton("Valider");
// on enregistre les actions ici boutonAnnuler = new JButton("Annuler");
boutonValider.addActionListener(this);
boutonAnnuler.addActionListener(this); // on enregistre les actions ici
boutonValider.addActionListener(this);
bas.add(boutonValider); boutonAnnuler.addActionListener(this);
bas.add(boutonAnnuler);
add(bas, BorderLayout.SOUTH); bas.add(boutonValider);
} bas.add(boutonAnnuler);
add(bas, BorderLayout.SOUTH);
@Override }
public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); @Override
public void actionPerformed(ActionEvent e) {
if (source == boutonAnnuler) { Object src = e.getSource();
dispose(); // ferme la fenêtre
} if (src == boutonAnnuler) {
else if (source == boutonValider) { // revenir à la fenêtre principale
String titre = champTitre.getText().trim(); Point pos = this.getLocation();
String contenu = champContenu.getText().trim(); parent.setLocation(pos);
if (titre.isEmpty() || contenu.isEmpty()) { parent.setVisible(true);
JOptionPane.showMessageDialog(this, this.setVisible(false);
"Veuillez remplir les deux champs.", return;
"Champs manquants", }
JOptionPane.WARNING_MESSAGE);
return; if (src == boutonValider) {
} String titre = champTitre.getText().trim();
String contenu = champContenu.getText().trim();
// pour linstant, juste un message (tu pourras relier à Main plus tard) if (titre.isEmpty() || contenu.isEmpty()) {
JOptionPane.showMessageDialog(this, JOptionPane.showMessageDialog(this, "Veuillez remplir les deux champs.");
"Rappel ajouté :\nTitre : " + titre + "\nContenu : " + contenu); return;
}
dispose();
} // TODO: ici appeler une méthode du parent pour ajouter le rappel
} // parent.ajouterRappel(titre, contenu);
}
parent.setVisible(true);
dispose();
}
}
}