Téléverser les fichiers vers "src/fr/iutfbleau/papillon"
Ajoute de la fenetre principale
This commit is contained in:
@@ -0,0 +1,99 @@
|
|||||||
|
// package fr.iutfbleau.papillon;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
public class FenetreAjout extends JFrame implements ActionListener {
|
||||||
|
|
||||||
|
private final JTextField champTitre;
|
||||||
|
private final JTextArea champContenu;
|
||||||
|
private final JButton boutonValider;
|
||||||
|
private final JButton boutonAnnuler;
|
||||||
|
|
||||||
|
public FenetreAjout() {
|
||||||
|
super("Ajouter un rappel");
|
||||||
|
|
||||||
|
setSize(300, 200);
|
||||||
|
setResizable(false);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
// Layout principal
|
||||||
|
setLayout(new BorderLayout(10, 10));
|
||||||
|
JPanel centre = new JPanel(new GridBagLayout());
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
c.insets = new Insets(4, 4, 4, 4);
|
||||||
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
add(centre, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// Titre
|
||||||
|
JLabel lblTitre = new JLabel("Titre :");
|
||||||
|
champTitre = new JTextField(20);
|
||||||
|
c.gridx = 0;
|
||||||
|
c.gridy = 0;
|
||||||
|
c.weightx = 0;
|
||||||
|
centre.add(lblTitre, c);
|
||||||
|
c.gridx = 1;
|
||||||
|
c.gridy = 0;
|
||||||
|
c.weightx = 1;
|
||||||
|
centre.add(champTitre, c);
|
||||||
|
|
||||||
|
// Contenu
|
||||||
|
JLabel lblContenu = new JLabel("Contenu :");
|
||||||
|
champContenu = new JTextArea(4, 20);
|
||||||
|
JScrollPane scroll = new JScrollPane(champContenu,
|
||||||
|
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
||||||
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
|
||||||
|
c.gridx = 0;
|
||||||
|
c.gridy = 1;
|
||||||
|
c.weightx = 0;
|
||||||
|
c.fill = GridBagConstraints.BOTH;
|
||||||
|
centre.add(lblContenu, c);
|
||||||
|
c.gridx = 1;
|
||||||
|
c.gridy = 1;
|
||||||
|
c.weightx = 1;
|
||||||
|
centre.add(scroll, c);
|
||||||
|
|
||||||
|
// Bas : boutons
|
||||||
|
JPanel bas = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
|
||||||
|
boutonValider = new JButton("Valider");
|
||||||
|
boutonAnnuler = new JButton("Annuler");
|
||||||
|
|
||||||
|
// on enregistre les actions ici
|
||||||
|
boutonValider.addActionListener(this);
|
||||||
|
boutonAnnuler.addActionListener(this);
|
||||||
|
|
||||||
|
bas.add(boutonValider);
|
||||||
|
bas.add(boutonAnnuler);
|
||||||
|
add(bas, BorderLayout.SOUTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Object source = e.getSource();
|
||||||
|
|
||||||
|
if (source == boutonAnnuler) {
|
||||||
|
dispose(); // ferme la fenêtre
|
||||||
|
}
|
||||||
|
else if (source == boutonValider) {
|
||||||
|
String titre = champTitre.getText().trim();
|
||||||
|
String contenu = champContenu.getText().trim();
|
||||||
|
|
||||||
|
if (titre.isEmpty() || contenu.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Veuillez remplir les deux champs.",
|
||||||
|
"Champs manquants",
|
||||||
|
JOptionPane.WARNING_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pour l’instant, juste un message (tu pourras relier à Main plus tard)
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Rappel ajouté :\nTitre : " + titre + "\nContenu : " + contenu);
|
||||||
|
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user