This commit is contained in:
pro.boooooo 2022-11-27 13:36:53 +01:00
parent 7dd1cbbf33
commit 24fda790b0
5 changed files with 69 additions and 65 deletions

View File

@ -8,8 +8,7 @@ package Test;
* */ * */
import javax.swing.*; import javax.swing.*;
import java.awt.GridBagLayout; import java.awt.*;
import java.awt.GridLayout;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
/** /**
@ -114,7 +113,6 @@ public class BFrame extends JFrame {
frame.setLocation(loca_x, loca_y); frame.setLocation(loca_x, loca_y);
frame.setSize(size_x, size_y); frame.setSize(size_x, size_y);
frame.getContentPane().add(content); frame.getContentPane().add(content);
JScrollPane scrollPane = new JScrollPane(); JScrollPane scrollPane = new JScrollPane();
frame.getContentPane().add(scrollPane); frame.getContentPane().add(scrollPane);
scrollPane.setViewportView(content); scrollPane.setViewportView(content);

View File

@ -16,9 +16,8 @@ import java.util.ArrayList;
import java.util.Objects; import java.util.Objects;
//test //test
import javax.swing.JDialog; import java.awt.Dimension;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.awt.GridLayout;
public class Controller implements ActionListener, ListSelectionListener { public class Controller implements ActionListener, ListSelectionListener {
private final BDatabase db; private final BDatabase db;
@ -52,28 +51,42 @@ public class Controller implements ActionListener, ListSelectionListener {
} }
/** /**
* Pour afficher une JTable * Pour afficher une JTable sans listener
* @param frame La fenetre *
* @param parent La fenetre qui sera bloque
* @param frameTitle Le titre de la fenetre
* @param size_x Taille en x
* @param size_y Taille en y
* @param loca_x Localisation en x
* @param loca_y Localisation en y
* @param liste La JTable * @param liste La JTable
* */ * */
private void Display(BFrame frame, JTable liste) { private void Display(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) {
JPanel forModal = new JPanel();
ListSelectionModel lsm = liste.getSelectionModel();
liste.getTableHeader().setReorderingAllowed(false); liste.getTableHeader().setReorderingAllowed(false);
liste.setFillsViewportHeight(true); liste.setFillsViewportHeight(true);
this.currentJTableUse = liste; this.currentJTableUse = liste;
JScrollPane scroll = new JScrollPane(liste); forModal.add(liste);
frame.getContentPane().add(scroll);
frame.openBFrame(); BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal);
} }
/** /**
* Pour afficher une JTable contenant un listener * Pour afficher une JTable contenant un listener
* @param frameTitle La fenetre *
* @param parent La fenetre qui sera bloque
* @param frameTitle Le titre de la fenetre
* @param size_x Taille en x
* @param size_y Taille en y
* @param loca_x Localisation en x
* @param loca_y Localisation en y
* @param liste La JTable * @param liste La JTable
* */ * */
private void DisplayWithListner(BFrame parent, String frameTitle, JTable liste) { private void DisplayWithListner(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) {
JPanel forModal = new JPanel(); JPanel forModal = new JPanel();
ListSelectionModel lsm = liste.getSelectionModel(); ListSelectionModel lsm = liste.getSelectionModel();
@ -85,9 +98,7 @@ public class Controller implements ActionListener, ListSelectionListener {
forModal.add(liste); forModal.add(liste);
// BETA BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal);
// TODO: Manque les colonnes et prends toute la surface
BFrame frame = new BFrame(frameTitle, 1, 1, 500, 500, parent, forModal);
} }
@Override @Override
@ -99,18 +110,6 @@ public class Controller implements ActionListener, ListSelectionListener {
String text = this.pv.getSearchStud(); String text = this.pv.getSearchStud();
if(Objects.equals(command, "pv::GetStudList")) { if(Objects.equals(command, "pv::GetStudList")) {
BFrame frame = new BFrame(
"Liste des eleves",
1,
1,
500,
500,
"GridLayout",
1,
1,
2
);
String[][] data = new String[this.e.size()][2]; String[][] data = new String[this.e.size()][2];
String[] titre = { String[] titre = {
@ -129,22 +128,18 @@ public class Controller implements ActionListener, ListSelectionListener {
data[i] = info; data[i] = info;
} }
Display(frame, this.createJTable(data, titre)); Display(
this.pv,
"Liste des etudiants",
350,
400,
this.pv.getX(),
this.pv.getY(),
this.createJTable(data, titre)
);
} }
else if(Objects.equals(command, "pv::GetListFiltered")) { else if(Objects.equals(command, "pv::GetListFiltered")) {
BFrame frame = new BFrame(
"Liste des eleves du " + groupeOption,
1,
1,
500,
500,
"GridLayout",
1,
1,
2
);
String[][] data = new String[this.e.size()][1]; String[][] data = new String[this.e.size()][1];
String[] titre = { String[] titre = {
@ -171,7 +166,15 @@ public class Controller implements ActionListener, ListSelectionListener {
data_final[x] = data[x]; data_final[x] = data[x];
} }
Display(frame, this.createJTable(data, titre)); Display(
this.pv,
"Liste d'eleve du " + groupeOption,
350,
400,
this.pv.getX(),
this.pv.getY(),
this.createJTable(data_final, titre)
);
} }
else if(Objects.equals(command, "pv::SearchStudentPer3Letters")) { else if(Objects.equals(command, "pv::SearchStudentPer3Letters")) {
@ -185,18 +188,6 @@ public class Controller implements ActionListener, ListSelectionListener {
} else { } else {
char[] beg = text.toCharArray(); char[] beg = text.toCharArray();
BFrame frame = new BFrame(
"Liste d'eleves d'ou les noms commence par " + beg[0] + beg[1] + beg[2],
1,
1,
500,
500,
"GridLayout",
1,
1,
2
);
ArrayList<String> filtreEleveNom = db.fetchAll("SELECT nom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'"); ArrayList<String> filtreEleveNom = db.fetchAll("SELECT nom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
ArrayList<String> filtreElevePrenom = db.fetchAll("SELECT prenom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'"); ArrayList<String> filtreElevePrenom = db.fetchAll("SELECT prenom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
ArrayList<String> filtreEleveGroupe = db.fetchAll("SELECT groupe FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'"); ArrayList<String> filtreEleveGroupe = db.fetchAll("SELECT groupe FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
@ -210,8 +201,6 @@ public class Controller implements ActionListener, ListSelectionListener {
"Erreur.", "Erreur.",
JOptionPane.ERROR_MESSAGE JOptionPane.ERROR_MESSAGE
); );
frame.closeBFrame();
} else { } else {
String[] titre = { String[] titre = {
"Nom", "Nom",
@ -229,18 +218,27 @@ public class Controller implements ActionListener, ListSelectionListener {
}; };
} }
Display(frame, this.createJTable(data, titre)); Display(
this.pv,
"Recherche",
350,
400,
this.pv.getX(),
this.pv.getY(),
this.createJTable(data, titre)
);
} }
} }
} }
else if(Objects.equals(command, "av::MoveStudGrup")) { else if(Objects.equals(command, "av::MoveStudGrup")) {
Object[][] data = new Object[this.e.size()][2]; Object[][] data = new Object[this.e.size()][3];
String[] titre = { String[] titre = {
"Nom", "Nom",
"Prenom", "Prenom",
"Groupe" "Groupe",
"Action"
}; };
for(int i = 0; i <= this.e.size()-1; i++) { for(int i = 0; i <= this.e.size()-1; i++) {
@ -248,12 +246,21 @@ public class Controller implements ActionListener, ListSelectionListener {
this.e.get(i).getNom(), this.e.get(i).getNom(),
this.e.get(i).getPrenom(), this.e.get(i).getPrenom(),
String.valueOf(this.e.get(i).getGroupe()), String.valueOf(this.e.get(i).getGroupe()),
"[DEPLACER]"
}; };
data[i] = info; data[i] = info;
} }
DisplayWithListner(this.av, "Deplacer un etudiant", this.createJTable(data, titre)); DisplayWithListner(
this.av,
"Deplacer un etudiant",
350,
400,
this.av.getX(),
this.av.getY(),
this.createJTable(data, titre)
);
} }
} }
@ -261,14 +268,13 @@ public class Controller implements ActionListener, ListSelectionListener {
public void valueChanged(ListSelectionEvent e) { public void valueChanged(ListSelectionEvent e) {
int[] cell; int[] cell;
Object value; Object value;
if (!e.getValueIsAdjusting())
{ if (!e.getValueIsAdjusting()) {
cell = this.currentJTableUse.getSelectedRows(); cell = this.currentJTableUse.getSelectedRows();
if (cell.length > 0) if (cell.length > 0) {
{
for (int i=0; i < 3; i++) { for (int i=0; i < 3; i++) {
TableModel tm = this.currentJTableUse.getModel(); TableModel tm = this.currentJTableUse.getModel();
value = tm.getValueAt(cell[0],i); value = tm.getValueAt(cell[0], i);
System.out.print(value + " "); System.out.print(value + " ");
} }