fonctionnalité crud
This commit is contained in:
@@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Main extends JFrame {
|
public class Main extends JFrame {
|
||||||
|
private final List<PanelRappel> listRpl = new ArrayList<>();
|
||||||
|
|
||||||
public Main(){
|
public Main(){
|
||||||
super("Papillon");
|
super("Papillon");
|
||||||
@@ -25,25 +29,31 @@ public class Main extends JFrame {
|
|||||||
// Colonne 0 : boutons
|
// Colonne 0 : boutons
|
||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
c.anchor = GridBagConstraints.NORTHWEST;
|
c.anchor = GridBagConstraints.NORTHWEST;
|
||||||
c.insets = new Insets(5, 5, 5, 5);
|
c.insets = new Insets(4, 4, 4, 4);
|
||||||
|
for(int i = 0; i< crud.size() ;i++){
|
||||||
c.gridx = 0;
|
c.gridx = 0;
|
||||||
c.gridy = 0;
|
c.gridy = i;
|
||||||
body.add(crud.get(0), c);
|
c.weighty = 0;
|
||||||
|
body.add(crud.get(i), c);
|
||||||
c.gridx = 0;
|
}
|
||||||
c.gridy = 1;
|
|
||||||
body.add(crud.get(1), c);
|
|
||||||
|
|
||||||
// Colonne 1 : liste verticale de Rappel dans un JScrollPane
|
// Colonne 1 : liste verticale de Rappel dans un JScrollPane
|
||||||
JPanel liste = new JPanel();
|
JPanel liste = new JPanel();
|
||||||
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
|
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
//rappels
|
//Rappels
|
||||||
|
GestionRappel g = new GestionRappel();
|
||||||
|
List<Rappel> listBd = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
listBd = g.lister();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(); // affiche l'erreur dans le terminal
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < listBd.size() ; i++) {
|
||||||
Rappel r = new Rappel();
|
PanelRappel r = new PanelRappel(listBd.get(i));
|
||||||
liste.add(r);
|
liste.add(r);
|
||||||
|
listRpl.add(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
JScrollPane scroll = new JScrollPane(
|
JScrollPane scroll = new JScrollPane(
|
||||||
@@ -56,17 +66,25 @@ public class Main extends JFrame {
|
|||||||
// place le scrollpane a droite, sur la hauteur des 2 lignes
|
// place le scrollpane a droite, sur la hauteur des 2 lignes
|
||||||
c.gridx = 1;
|
c.gridx = 1;
|
||||||
c.gridy = 0;
|
c.gridy = 0;
|
||||||
c.gridheight = 2;
|
c.gridheight = 3;
|
||||||
c.fill = GridBagConstraints.BOTH;
|
c.fill = GridBagConstraints.BOTH;
|
||||||
c.insets = new Insets(0, 0, 0, 0);
|
c.insets = new Insets(0, 0, 0, 0);
|
||||||
c.weightx = 1.0; // prend la largeur dispo
|
c.weightx = 1.0; // prend la largeur dispo
|
||||||
c.weighty = 1.0; // prend la hauteur dispo
|
c.weighty = 1.0; // prend la hauteur dispo
|
||||||
body.add(scroll, c);
|
body.add(scroll, c);
|
||||||
|
|
||||||
|
// barre en bas
|
||||||
|
JLabel txtbarre = new JLabel("-", SwingConstants.CENTER);
|
||||||
|
JPanel barre = new JPanel();
|
||||||
|
barre.add(txtbarre);
|
||||||
|
barre.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
|
||||||
|
// barre.setBackground(Color.GRAY);
|
||||||
|
|
||||||
// Conteneur racine
|
// Conteneur racine
|
||||||
JPanel root = new JPanel(new BorderLayout());
|
JPanel root = new JPanel(new BorderLayout());
|
||||||
root.add(titre, BorderLayout.NORTH);
|
root.add(titre, BorderLayout.NORTH);
|
||||||
root.add(body, BorderLayout.CENTER);
|
root.add(body, BorderLayout.CENTER);
|
||||||
|
root.add(barre, BorderLayout.SOUTH);
|
||||||
setContentPane(root);
|
setContentPane(root);
|
||||||
|
|
||||||
// Taille fixe
|
// Taille fixe
|
||||||
@@ -76,23 +94,8 @@ public class Main extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<PanelRappel> getPanelRpl(){
|
||||||
public void ouvrirFenetreAjout() {
|
return listRpl;
|
||||||
FenetreAjout f = new FenetreAjout(this);
|
|
||||||
// cacher la fenetre actuelle et montrer celle d ajout
|
|
||||||
|
|
||||||
// récupère la position actuelle de Main
|
|
||||||
Point pos = this.getLocation();
|
|
||||||
f.setLocation(pos); // place FenetreAjout au même endroit
|
|
||||||
|
|
||||||
f.setVisible(true);
|
|
||||||
this.setVisible(false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
Main f = new Main();
|
|
||||||
f.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user