ajout du trie

This commit is contained in:
2025-10-25 20:34:02 +02:00
parent a8103f87dc
commit e3b13a908a
3 changed files with 100 additions and 39 deletions
+19
View File
@@ -0,0 +1,19 @@
import javax.swing.*;
public class ChoixRang extends JComboBox<String> {
public ChoixRang(){
super(new String[]{"Tout", "Rang 1", "Rang 2", "Rang 3","Rang 4", "Rang 5"});
this.setSelectedItem("Tout");
this.addActionListener(this);
}
public void tirage(Main main){
main.setTrie(this.getSelectedIndex());
main.maj();
}
}
+80 -37
View File
@@ -2,16 +2,24 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class Main extends JFrame {
private final List<PanelRappel> listRpl = new ArrayList<>();
public class Main extends JFrame implements ActionListener{
private List<PanelRappel> listRpl = new ArrayList<>();
private JPanel liste = new JPanel();
private ChoixRang trier = new ChoixRang();
private JPanel root = new JPanel(new BorderLayout());
public Main(){
super("Papillon");
ImageIcon logo = new ImageIcon("logo.png");
setIconImage(logo.getImage());
trier = new ChoixRang();
trier.addActionListener(this);
// Taille fixe
setSize(350, 250);
setResizable(false);
@@ -23,9 +31,7 @@ public class Main extends JFrame {
titre.setBorder(BorderFactory.createEmptyBorder(6,10,6,10));
// titre.setBackground(Color.CYAN);
// ----- Grille centrale : boutons a gauche + liste scrollable a droite -----
// ----- Grille centrale -----
JPanel body = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
@@ -36,31 +42,21 @@ public class Main extends JFrame {
c.anchor = GridBagConstraints.NORTHWEST;
c.insets = new Insets(4, 4, 4, 4);
for(int i = 0; i< crud.size() ;i++){
c.gridx = 0;
c.gridy = i;
c.gridx = i;
c.gridy = 4;
c.weighty = 0;
c.weightx = 1;
body.add(crud.get(i), c);
}
// Colonne 1 : liste verticale de Rappel dans un JScrollPane
JPanel liste = new JPanel();
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
liste = new JPanel();
//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 < listBd.size() ; i++) {
PanelRappel r = new PanelRappel(listBd.get(i));
liste.add(r);
listRpl.add(r);
}
this.setTrie(trier.getSelectedIndex());
liste=this.getRPanel();
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
JScrollPane scroll = new JScrollPane(
liste,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
@@ -69,31 +65,26 @@ try {
scroll.getVerticalScrollBar().setUnitIncrement(16); // molette fluide
// place le scrollpane a droite, sur la hauteur des 2 lignes
c.gridx = 1;
c.gridy = 0;
c.gridheight = 3;
c.gridx = 0; c.gridy = 1; c.gridwidth = 3;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(0, 0, 0, 0);
c.weightx = 1.0; // prend la largeur dispo
c.weighty = 1.0; // prend la hauteur dispo
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);
c.gridx=0; c.gridy=0;
c.weightx = 0.0; c.weighty = 0.0;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.SOUTHEAST;
c.insets = new Insets(1, 1, 1, 1);
body.add(trier,c);
// Conteneur racine
JPanel root = new JPanel(new BorderLayout());
root.add(titre, BorderLayout.NORTH);
root.add(body, BorderLayout.CENTER);
root.add(barre, BorderLayout.SOUTH);
setContentPane(root);
}
@@ -101,4 +92,56 @@ public List<PanelRappel> getPanelRpl(){
return listRpl;
}
public void maj(){
liste = this.getRPanel();
liste.revalidate(); // recalcul du layout
liste.repaint();
this.revalidate();
this.repaint();
}
public void setTrie(int rang){
listRpl = new ArrayList<>();
GestionRappel g = new GestionRappel();
List<Rappel> listBd = new ArrayList<>();
try {
listBd = g.lister();
} catch (Exception ex) {
ex.printStackTrace();
}
if(rang>0){
for(int i=0;i<listBd.size();i++){
PanelRappel rappel = new PanelRappel(listBd.get(i), this);
if(listBd.get(i).getRang()==rang){
liste.add(rappel);
listRpl.add(rappel);
}
}
}else{
for (int i = 0; i < listBd.size() ; i++) {
PanelRappel r = new PanelRappel(listBd.get(i), this);
liste.add(r);
listRpl.add(r);
}
}
}
public JPanel getRPanel(){
return liste;
}
@Override
public void actionPerformed(ActionEvent ea) {
liste.removeAll();
trier.tirage(this);
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
import javax.swing.*;
import java.awt.*;
public class Start{
public static void main(String[] args) {