Ajout des boutons crud + gestion de la modification et de l'ajout
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// package fr.iutfbleau.papillon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class BtnAjouter extends JButton implements ActionListener{
|
||||
private GestionRappel ges;
|
||||
private Main main;
|
||||
|
||||
public BtnAjouter(Main main){
|
||||
super("Ajouter");
|
||||
this.main = main;
|
||||
setPreferredSize(new Dimension(120,25));
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if(e.getSource()==this){
|
||||
|
||||
FenetreAjout f = new FenetreAjout(main);
|
||||
// cacher la fenetre actuelle et montrer celle d ajout
|
||||
f.setLocation(main.getLocation()); // récupère la position actuelle de Main,place FenetreAjout au même endroit
|
||||
f.setVisible(true);
|
||||
main.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// package fr.iutfbleau.papillon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class BtnModifier extends JButton implements ActionListener{
|
||||
|
||||
private GestionRappel ges;
|
||||
private Rappel rappel;
|
||||
private Main main;
|
||||
|
||||
public BtnModifier(Main main){
|
||||
super("Modifier");
|
||||
this.main = main;
|
||||
setPreferredSize(new Dimension(120,25));
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
|
||||
if (e.getSource() == this) {
|
||||
ges = new GestionRappel();
|
||||
int count = 0;
|
||||
List<PanelRappel> listRpl = new ArrayList<>();
|
||||
PanelRappel pr;
|
||||
|
||||
listRpl = main.getPanelRpl();
|
||||
for(int i = 0; i<listRpl.size();i++){
|
||||
pr = listRpl.get(i);
|
||||
if(pr.getSelection()==true){
|
||||
count++;
|
||||
rappel=pr.getRappel();
|
||||
}
|
||||
}
|
||||
|
||||
if(count==0){
|
||||
JOptionPane.showMessageDialog(main, "Sélectionnez 1 rappel à modifier");
|
||||
return;
|
||||
}
|
||||
if(count==1){
|
||||
|
||||
FenetreModif f = new FenetreModif(main,rappel,rappel.getTitre(),rappel.getContenu());
|
||||
f.setVisible(true);
|
||||
main.setVisible(false);
|
||||
}
|
||||
|
||||
if(count>1){
|
||||
JOptionPane.showMessageDialog(main, "Sélectionnez seulement 1 rappel à modifier");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// package fr.iutfbleau.papillon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class BtnSupprimer extends JButton implements ActionListener{
|
||||
private GestionRappel ges;
|
||||
private Main main;
|
||||
|
||||
public BtnSupprimer(Main main){
|
||||
super("Supprimer");
|
||||
this.main = main;
|
||||
setPreferredSize(new Dimension(120,25));
|
||||
addActionListener(this);
|
||||
}
|
||||
public void actionPerformed(ActionEvent e){
|
||||
|
||||
if(e.getSource()==this){
|
||||
|
||||
ges = new GestionRappel();
|
||||
int count = 0;
|
||||
List<PanelRappel> listRpl = new ArrayList<>();
|
||||
PanelRappel pr;
|
||||
|
||||
listRpl = main.getPanelRpl();
|
||||
for(int i = 0; i<listRpl.size();i++){
|
||||
pr = listRpl.get(i);
|
||||
if(pr.getSelection()==true){
|
||||
count++;
|
||||
try{
|
||||
ges.supprimerParId(pr.getId());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(); // affiche l'erreur dans le terminal
|
||||
}
|
||||
}
|
||||
}
|
||||
if(count==0){
|
||||
JOptionPane.showMessageDialog(main, "Sélectionnez les rappels que vous souhaiter supprimer !");
|
||||
}else{
|
||||
JOptionPane.showMessageDialog(main, "Les rappels on bien étaient supprimé.");
|
||||
new Main().setVisible(true);
|
||||
main.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GestionAjout extends ArrayList<JButton> implements ActionListener{
|
||||
|
||||
private final JButton boutonValider;
|
||||
private final JButton boutonAnnuler;
|
||||
|
||||
private final JTextField champTitre;
|
||||
private final JTextArea champContenu;
|
||||
private JComboBox<Integer> rang;
|
||||
private final JComboBox<String> comboTheme;
|
||||
private final Main parent;
|
||||
private final JFrame f;
|
||||
|
||||
public GestionAjout(JFrame f, Main parent, JTextField champTitre, JTextArea champContenu, JComboBox<Integer> rang, JComboBox<String> comboTheme){
|
||||
|
||||
this.f = f;
|
||||
this.parent = parent;
|
||||
this.champTitre = champTitre;
|
||||
this.champContenu = champContenu;
|
||||
this.rang = rang;
|
||||
this.comboTheme = comboTheme;
|
||||
|
||||
boutonValider = new JButton("Valider");
|
||||
boutonAnnuler = new JButton("Annuler");
|
||||
this.add(boutonValider);
|
||||
this.add(boutonAnnuler);
|
||||
boutonValider.addActionListener(this);
|
||||
boutonAnnuler.addActionListener(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object src = e.getSource();
|
||||
|
||||
if (src == boutonAnnuler) {
|
||||
// revenir à la fenêtre principale
|
||||
Point pos = f.getLocation();
|
||||
|
||||
parent.setLocation(pos);
|
||||
parent.setVisible(true);
|
||||
f.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()) {
|
||||
JOptionPane.showMessageDialog(f, "Veuillez remplir tout le titre.", "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(f.getLocation());
|
||||
reParent.setVisible(true);
|
||||
f.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GestionModif extends ArrayList<JButton> implements ActionListener{
|
||||
|
||||
private final JButton boutonValider;
|
||||
private final JButton boutonAnnuler;
|
||||
|
||||
private final JTextField champTitre;
|
||||
private final JTextArea champContenu;
|
||||
private JComboBox<Integer> rang;
|
||||
private final JComboBox<String> comboTheme;
|
||||
private Rappel rappel;
|
||||
|
||||
private GestionRappel ges = new GestionRappel();
|
||||
private final Main parent;
|
||||
private final JFrame f;
|
||||
|
||||
public GestionModif(JFrame f, Main parent, JTextField champTitre, JTextArea champContenu, JComboBox<Integer> rang, JComboBox<String> comboTheme, Rappel r){
|
||||
|
||||
this.f = f;
|
||||
this.parent = parent;
|
||||
this.champTitre = champTitre;
|
||||
this.champContenu = champContenu;
|
||||
this.rang = rang;
|
||||
this.comboTheme = comboTheme;
|
||||
this.rappel = r;
|
||||
|
||||
boutonValider = new JButton("Valider");
|
||||
boutonAnnuler = new JButton("Annuler");
|
||||
this.add(boutonValider);
|
||||
this.add(boutonAnnuler);
|
||||
boutonValider.addActionListener(this);
|
||||
boutonAnnuler.addActionListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object src = e.getSource();
|
||||
|
||||
if (src == boutonAnnuler) {
|
||||
|
||||
parent.setLocation(f.getLocation());
|
||||
parent.setVisible(true);
|
||||
f.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
if (src == boutonValider) {
|
||||
String t = champTitre.getText().trim();
|
||||
String c = champContenu.getText().trim();
|
||||
int r = (Integer) rang.getSelectedItem();
|
||||
String th = (String) comboTheme.getSelectedItem();
|
||||
|
||||
if (t.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(f, "Veuillez remplir le titre.", "Champs manquants", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// MAJ directe du rappel
|
||||
|
||||
rappel.setTitre(t);
|
||||
rappel.setContenu(c);
|
||||
rappel.setRang(r);
|
||||
rappel.setTheme(th);
|
||||
try{
|
||||
ges.modifierParId(rappel.getId(), rappel);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Main reParent = new Main();
|
||||
reParent.setLocation(f.getLocation());
|
||||
reParent.setVisible(true);
|
||||
f.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user