fonctionnalité crud

This commit is contained in:
2025-10-23 00:33:21 +02:00
parent b1ca41dcc1
commit 5e6155861a
+54 -43
View File
@@ -8,8 +8,14 @@ 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 JTextField rang; private Integer[] nombres = {1, 2, 3, 4, 5};
private final JTextField theme; private JComboBox<Integer> rang = new JComboBox<>(nombres);
private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Gris"};
private final JComboBox<String> comboTheme = new JComboBox<>(nomsCouleurs);
private final JButton boutonValider; private final JButton boutonValider;
private final JButton boutonAnnuler; private final JButton boutonAnnuler;
private final Main parent; private final Main parent;
@@ -20,7 +26,6 @@ public class FenetreAjout extends JFrame implements ActionListener {
setSize(350, 250); setSize(350, 250);
setResizable(false); setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Layout principal // Layout principal
@@ -34,64 +39,51 @@ public class FenetreAjout extends JFrame implements ActionListener {
// Titre // Titre
JLabel lblTitre = new JLabel("Titre :"); JLabel lblTitre = new JLabel("Titre :");
champTitre = new JTextField(20); champTitre = new JTextField(20);
c.gridx = 0; c.gridx = 0; c.gridy = 1; c.weightx = 0;
c.gridy = 1;
c.weightx = 0;
centre.add(lblTitre, c); centre.add(lblTitre, c);
c.gridx = 1; c.gridx = 1; c.gridy = 1; c.weightx = 1;
c.gridy = 1;
c.weightx = 1;
centre.add(champTitre, c); centre.add(champTitre, c);
// Contenu // Contenu
JLabel lblContenu = new JLabel("Contenu :"); JLabel lblContenu = new JLabel("Contenu :");
champContenu = new JTextArea(4, 20); champContenu = new JTextArea(4, 20);
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 scroll = new JScrollPane(champContenu,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
c.gridx = 0; c.gridx = 0; c.gridy = 2; c.weightx = 0;
c.gridy = 2;
c.weightx = 0;
c.fill = GridBagConstraints.BOTH; c.fill = GridBagConstraints.BOTH;
centre.add(lblContenu, c); centre.add(lblContenu, c);
c.gridx = 1; c.gridx = 1; c.gridy = 2; c.weightx = 1; c.weighty = 1.0;
c.gridy = 2;
c.weightx = 1;
c.weighty = 1.0; // prend la hauteur dispo
centre.add(scroll, c); centre.add(scroll, c);
// Rang // Rang
JLabel lblrang = new JLabel("Rang :"); JLabel lblrang = new JLabel("Rang :");
rang = new JTextField(20); 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; // prend la hauteur dispo
centre.add(lblrang, c); centre.add(lblrang, c);
c.gridx = 1; c.gridx = 1; c.gridy = 3; c.weightx = 1;
c.gridy = 3;
c.weightx = 1;
centre.add(rang, c); centre.add(rang, c);
// theme
JLabel lbltheme = new JLabel("Theme :");
theme = new JTextField(20); // Theme
c.gridx = 0; c.gridx = 0; c.gridy = 4; c.weightx = 0;
c.gridy = 4; centre.add(new JLabel("Theme :"), c);
c.weightx = 0;
centre.add(lbltheme, c); // liste déroulante de couleurs
c.gridx = 1; c.gridx = 1; c.gridy = 4; c.weightx = 1;
c.gridy = 4; comboTheme.setRenderer(new CouleurList());
c.weightx = 1; comboTheme.setSelectedItem("Bleu"); // valeur par défaut
centre.add(theme, c); centre.add(comboTheme, c);
// Bas : boutons // Bas : boutons
JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
boutonValider = new JButton("Valider"); boutonValider = new JButton("Valider");
boutonAnnuler = new JButton("Annuler"); boutonAnnuler = new JButton("Annuler");
// on enregistre les actions ici
boutonValider.addActionListener(this); boutonValider.addActionListener(this);
boutonAnnuler.addActionListener(this); boutonAnnuler.addActionListener(this);
@@ -100,6 +92,12 @@ public class FenetreAjout extends JFrame implements ActionListener {
add(bas, BorderLayout.SOUTH); add(bas, BorderLayout.SOUTH);
} }
public Color getCouleurChoix() {
String nom = (String) comboTheme.getSelectedItem();
return CouleurList.couleurDe(nom);
}
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Object src = e.getSource(); Object src = e.getSource();
@@ -107,25 +105,38 @@ public class FenetreAjout extends JFrame implements ActionListener {
if (src == boutonAnnuler) { if (src == boutonAnnuler) {
// revenir à la fenêtre principale // revenir à la fenêtre principale
Point pos = this.getLocation(); Point pos = this.getLocation();
parent.setLocation(pos); parent.setLocation(pos);
parent.setVisible(true); parent.setVisible(true);
this.setVisible(false); this.dispose();
return; return;
} }
if (src == boutonValider) { if (src == boutonValider) {
String titre = champTitre.getText().trim(); String titre = champTitre.getText().trim();
String contenu = champContenu.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()) { if (titre.isEmpty() || contenu.isEmpty()) {
JOptionPane.showMessageDialog(this, "Veuillez remplir les deux champs."); JOptionPane.showMessageDialog(this, "Veuillez remplir tout les champs.", "Champs manquants", JOptionPane.WARNING_MESSAGE);
return; return;
}else{
try{
g.ajouter(new Rappel(titre,contenu,cTheme,Nrang));
} catch (Exception ex) {
ex.printStackTrace(); // affiche l'erreur dans le terminal
} }
// TODO: ici appeler une méthode du parent pour ajouter le rappel }
// parent.ajouterRappel(titre, contenu);
Main reParent = new Main();
parent.setVisible(true); reParent.setLocation(this.getLocation());
reParent.setVisible(true);
dispose(); dispose();
} }
} }