Maj de la fenetre ajout
This commit is contained in:
@@ -2,31 +2,27 @@
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
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 JTextField champTitre;
|
||||||
private final JTextArea champContenu;
|
private final JTextArea champContenu;
|
||||||
private Integer[] nombres = {1, 2, 3, 4, 5};
|
private Integer[] nombres = {1, 2, 3, 4, 5};
|
||||||
private JComboBox<Integer> rang = new JComboBox<>(nombres);
|
private JComboBox<Integer> rang = new JComboBox<>(nombres);
|
||||||
|
|
||||||
|
private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Rose"};
|
||||||
private final String[] nomsCouleurs = {"Bleu", "Rouge", "Vert", "Jaune", "Gris"};
|
|
||||||
private final JComboBox<String> comboTheme = new JComboBox<>(nomsCouleurs);
|
private final JComboBox<String> comboTheme = new JComboBox<>(nomsCouleurs);
|
||||||
|
|
||||||
|
private GestionAjout listBtnAjout;
|
||||||
|
|
||||||
|
|
||||||
private final JButton boutonValider;
|
|
||||||
private final JButton boutonAnnuler;
|
|
||||||
private final Main parent;
|
|
||||||
|
|
||||||
public FenetreAjout(Main parent) {
|
public FenetreAjout(Main parent) {
|
||||||
super("Ajouter un rappel");
|
super("Ajouter un rappel");
|
||||||
this.parent = parent;
|
ImageIcon logo = new ImageIcon("logo.png");
|
||||||
|
setIconImage(logo.getImage());
|
||||||
|
|
||||||
setSize(350, 250);
|
setSize(350, 250);
|
||||||
|
setAlwaysOnTop(true);
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
@@ -40,42 +36,60 @@ 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(50);
|
||||||
c.gridx = 0; c.gridy = 1; c.weightx = 0;
|
champTitre.setDocument(new LimiteContenu(50));
|
||||||
|
c.gridx = 0;
|
||||||
|
c.gridy = 1;
|
||||||
|
c.weightx = 0;
|
||||||
centre.add(lblTitre, c);
|
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);
|
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.setDocument(new LimiteContenu(200));
|
||||||
champContenu.setLineWrap(true); // active le retour à la ligne
|
champContenu.setLineWrap(true); // active le retour à la ligne
|
||||||
champContenu.setWrapStyleWord(true); // évite de couper un mot en plein milieu
|
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.gridy = 2; c.weightx = 0;
|
c.gridx = 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.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);
|
centre.add(scroll, c);
|
||||||
|
|
||||||
// Rang
|
// Rang
|
||||||
JLabel lblrang = new JLabel("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);
|
centre.add(lblrang, c);
|
||||||
c.gridx = 1; c.gridy = 3; c.weightx = 1;
|
c.gridx = 1;
|
||||||
centre.add(rang, c);
|
c.gridy = 3;
|
||||||
|
c.weightx = 1;
|
||||||
|
centre.add(rang, c);
|
||||||
|
|
||||||
// Theme
|
// 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);
|
centre.add(new JLabel("Theme :"), c);
|
||||||
|
|
||||||
// liste déroulante de couleurs
|
// 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.setRenderer(new CouleurList());
|
||||||
comboTheme.setSelectedItem("Bleu"); // valeur par défaut
|
comboTheme.setSelectedItem("Bleu"); // valeur par défaut
|
||||||
centre.add(comboTheme, c);
|
centre.add(comboTheme, c);
|
||||||
@@ -83,14 +97,10 @@ public class FenetreAjout extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
// 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");
|
|
||||||
boutonAnnuler = new JButton("Annuler");
|
|
||||||
|
|
||||||
boutonValider.addActionListener(this);
|
listBtnAjout = new GestionAjout(this,parent,champTitre,champContenu,rang,comboTheme);
|
||||||
boutonAnnuler.addActionListener(this);
|
bas.add(listBtnAjout.get(0));
|
||||||
|
bas.add(listBtnAjout.get(1));
|
||||||
bas.add(boutonValider);
|
|
||||||
bas.add(boutonAnnuler);
|
|
||||||
add(bas, BorderLayout.SOUTH);
|
add(bas, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,48 +109,4 @@ public class FenetreAjout extends JFrame implements ActionListener {
|
|||||||
return CouleurList.couleurDe(nom);
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user