1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
public class PanelCritere extends JFrame implements ActionListener{
private static final long serialVersionUID = 1758109648073718652L;
private JFrame fenetreCritere;
private JPanel panel_critere;
//Déclaration des champs pour le titre
private JPanel info_titre;
private JPanel pan_info_titre;
private JLabel titre;
//Déclaration des champs pour la section
private JPanel info_sections;
private JCheckBoxMenuItem nom_sections;
private JComboBox sections;
String[] section = { "ING1LM", "ING1JV", "SIGL2", "SRT2","TRSE2","SIGL3","SRT3","TRSE3"};
//Déclaration des champs pour le nom
private JPanel info_nom;
private JPanel pan_info_nom;
private JCheckBoxMenuItem nom_nom;
private JPanel pan_nom;
private JTextField nom;
//Déclaration des champs pour le bouton rechercher
private JPanel info_rechercher;
private JPanel pan_info_rechercher;
private JButton rechercher;
//Déclaration des champs pour l'affichage des étudiants
private JScrollPane scrollpane;
private DefaultListModel dlm;
private JList lEtudiants;
private JPanel etudiant;
//test
String[] colonnes = { "ID", "NOM", "PRENOM", "SECTION","NOTE1","NOTE2","NOTE3","MOYENNE"};
private JTable table = null;
//Déclaration des champs pour l'édition ou la suppression des étudiants
private JPanel ico;
private JButton edit;
private JButton sup;
ListeEtudiant l1 = new ListeEtudiant();
ListeSection s1 = new ListeSection();
//Constructeur
public PanelCritere( ListeEtudiant ls, ListeSection ss) {
l1=ls;
s1=ss;
fenetreCritere = new JFrame();
fenetreCritere.setSize(700, 500);
panel_critere = new JPanel();
//panel = new JPanel();
//Initialisation des champs pour le titre
info_titre = new JPanel();
pan_info_titre = new JPanel();
titre = new JLabel("RECHERCHER UN ETUDIANT");
//Initialisation des champs pour la section
info_sections = new JPanel();
new JPanel();
nom_sections = new JCheckBoxMenuItem("section");
nom_sections.addActionListener(this);
nom_sections.setState(false);
new JPanel();
sections = new JComboBox(section);
//Initialisation des champs pour le nom
info_nom = new JPanel();
pan_info_nom = new JPanel();
nom_nom = new JCheckBoxMenuItem("nom");
nom_nom.addActionListener(this);
nom_nom.setState(false);
pan_nom = new JPanel();
nom = new JTextField(20);
//Initialisation des champs pour le bouton rechercher
info_rechercher = new JPanel();
pan_info_rechercher = new JPanel();
rechercher = new JButton("Rechercher");
rechercher.addActionListener(this);
//Initialisation des champs pour l'affichage des étudiants
scrollpane = new JScrollPane();
dlm = new DefaultListModel();
lEtudiants = new JList(dlm);
etudiant = new JPanel();
//Initialisation des champs pour l'édition ou la suppression des étudiants
ico = new JPanel();
edit = new JButton(new ImageIcon("C:\\wamp\\www\\JAVA\\Ecole\\images\\editer.png"));
edit.addActionListener(this);
sup = new JButton(new ImageIcon("C:\\wamp\\www\\JAVA\\Ecole\\images\\supprimer.png"));
sup.addActionListener(this);
//Ajout du panel à la fenetre et affichage selon l'axe des ordonnées
fenetreCritere.add(panel_critere);
panel_critere.setLayout(new BoxLayout(panel_critere, BoxLayout.Y_AXIS));
//Ajout du titre au panel
panel_critere.add(info_titre);
info_titre.setLayout(new BorderLayout());
info_titre.add(pan_info_titre,BorderLayout.CENTER);
pan_info_titre.add(titre);
titre.setFont(new Font("serif", Font.PLAIN, 20));
panel_critere.add(Box.createRigidArea(new Dimension(0,10)));
//ajout des champs du choix section au panel
panel_critere.add(info_sections);
info_sections.add(nom_sections);
info_sections.add(sections);
sections.setEnabled(false);
//ajout des champs du choix nom au panel
panel_critere.add(info_nom);
info_nom.add(pan_info_nom);
info_nom.add(pan_nom);
pan_info_nom.add(nom_nom);
pan_nom.add(nom);
nom.setEditable(false);
//Mise en place d'un espacement
panel_critere.add(Box.createRigidArea(new Dimension(0,10)));
//ajout du bouton rechercher au panel
panel_critere.add(info_rechercher);
info_rechercher.setLayout(new BorderLayout());
info_rechercher.add(pan_info_rechercher,BorderLayout.CENTER);
pan_info_rechercher.add(rechercher);
panel_critere.add(Box.createRigidArea(new Dimension(0,30)));
fenetreCritere.setVisible(true);
}
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
Object source = e.getSource() ;
//Cas selon appui sur la checkbox section ou nom
if (source == nom_sections){
if (nom_sections.getState()){sections.setEnabled(true);nom.setEditable(false);nom_nom.setSelected(false);}
else{sections.setEnabled(false);}
}
if (source == nom_nom){
if (nom_nom.getState()){nom.setEditable(true);sections.setEnabled(false);nom_sections.setSelected(false);}
else {nom.setEditable(false);}
}
//Action lors de l'appui sur le bouton rechercher
if (source == rechercher){
etudiant.setVisible(false);
ico.setLayout(new BoxLayout(ico,BoxLayout.Y_AXIS));
scrollpane.getViewport().add(lEtudiants);
ico.add(edit);
ico.add(sup);
panel_critere.add(ico);
//Si la recherche se fait par le nom
if (nom_nom.getState()){
String val_nom = nom.getText();
int nrows = l1.rechercherEtudiantByNom(val_nom).size();
int ncolumns = 8;
Vector rows = new Vector();
for (int i = 0; i < nrows; i++) {
String nom = l1.rechercherEtudiantByNom(val_nom).get(i).getNom();
String prenom = l1.rechercherEtudiantByNom(val_nom).get(i).getPrenom();
String section = l1.rechercherEtudiantByNom(val_nom).get(i).getSection();
Double note1 = l1.getNote1Etudiant2(i);
Double note2 = l1.getNote2Etudiant2(i);
Double note3 = l1.getNote3Etudiant2(i);
Double moyenne = l1.getMoyenneEtudiant2(i);
int id = l1.getIDEtudiant(nom, prenom);
Object[] rowi = {id,nom,prenom,section,note1,note2,note3,moyenne};
Vector row = new Vector();
for (int j = 0; j < ncolumns; j++) {
row.addElement(rowi[j]);
}
rows.addElement(row);
}
Vector columns = new Vector();
for (int i = 0; i < ncolumns; i++) {
columns.addElement(colonnes[i]);
}
//Rafraichissement du tableau
table = new JTable();
DefaultTableModel defaultTable = (DefaultTableModel)table.getModel();
defaultTable = new DefaultTableModel(rows,columns);
defaultTable.fireTableDataChanged();
table.setModel(defaultTable);
//Changer couleur des entêtes du tableau
table.getTableHeader().setDefaultRenderer(new DefaultTableCellRenderer(){
/**
*
*/
private static final long serialVersionUID = 4330546965480623122L;
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
Font displayFont = new Font("Arial", Font.BOLD, 13);
c.setFont(displayFont);
c.setBackground(Color.blue);
return c;
}
});
//Mettre en mode checkbox les sections
TableColumn sectionColumn = table.getColumnModel().getColumn(3);
sectionColumn.setCellEditor(new DefaultCellEditor(sections));
//Mise en place du menu déroulant
JScrollPane scrollPane = new JScrollPane(table);
etudiant.setLayout(new BorderLayout());
etudiant.add(scrollPane,BorderLayout.CENTER);
}
if (nom_sections.getState()){
String val_section = (String) sections.getSelectedItem();
int taille = l1.compteEtudiantParSection(val_section);
System.out.println(taille);
}
panel_critere.add(etudiant);
etudiant.setVisible(true);
} |
Partager