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 javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Arrays;
public class Main extends JFrame { public class Main extends JFrame implements ActionListener{
private final List<PanelRappel> listRpl = new ArrayList<>();
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(){ public Main(){
super("Papillon"); super("Papillon");
ImageIcon logo = new ImageIcon("logo.png");
setIconImage(logo.getImage());
trier = new ChoixRang();
trier.addActionListener(this);
// Taille fixe // Taille fixe
setSize(350, 250); setSize(350, 250);
setResizable(false); setResizable(false);
@@ -23,9 +31,7 @@ public class Main extends JFrame {
titre.setBorder(BorderFactory.createEmptyBorder(6,10,6,10)); titre.setBorder(BorderFactory.createEmptyBorder(6,10,6,10));
// titre.setBackground(Color.CYAN); // titre.setBackground(Color.CYAN);
// ----- Grille centrale -----
// ----- Grille centrale : boutons a gauche + liste scrollable a droite -----
JPanel body = new JPanel(new GridBagLayout()); JPanel body = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
@@ -36,31 +42,21 @@ public class Main extends JFrame {
c.anchor = GridBagConstraints.NORTHWEST; c.anchor = GridBagConstraints.NORTHWEST;
c.insets = new Insets(4, 4, 4, 4); c.insets = new Insets(4, 4, 4, 4);
for(int i = 0; i< crud.size() ;i++){ for(int i = 0; i< crud.size() ;i++){
c.gridx = 0; c.gridx = i;
c.gridy = i; c.gridy = 4;
c.weighty = 0; c.weighty = 0;
c.weightx = 1;
body.add(crud.get(i), c); body.add(crud.get(i), c);
} }
// Colonne 1 : liste verticale de Rappel dans un JScrollPane // Colonne 1 : liste verticale de Rappel dans un JScrollPane
JPanel liste = new JPanel(); liste = new JPanel();
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
//Rappels //Rappels
GestionRappel g = new GestionRappel(); this.setTrie(trier.getSelectedIndex());
List<Rappel> listBd = new ArrayList<>(); liste=this.getRPanel();
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);
}
liste.setLayout(new BoxLayout(liste, BoxLayout.Y_AXIS));
JScrollPane scroll = new JScrollPane( JScrollPane scroll = new JScrollPane(
liste, liste,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
@@ -69,31 +65,26 @@ try {
scroll.getVerticalScrollBar().setUnitIncrement(16); // molette fluide scroll.getVerticalScrollBar().setUnitIncrement(16); // molette fluide
// 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 = 0; c.gridy = 1; c.gridwidth = 3;
c.gridy = 0;
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 c.gridx=0; c.gridy=0;
JLabel txtbarre = new JLabel("-", SwingConstants.CENTER); c.weightx = 0.0; c.weighty = 0.0;
JPanel barre = new JPanel(); c.fill = GridBagConstraints.NONE;
barre.add(txtbarre); c.anchor = GridBagConstraints.SOUTHEAST;
barre.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); c.insets = new Insets(1, 1, 1, 1);
// barre.setBackground(Color.GRAY); body.add(trier,c);
// Conteneur racine // Conteneur racine
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);
} }
@@ -101,4 +92,56 @@ public List<PanelRappel> getPanelRpl(){
return listRpl; 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 class Start{
public static void main(String[] args) { public static void main(String[] args) {