146 lines
4.9 KiB
Java
146 lines
4.9 KiB
Java
package fenetres;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Font;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JTable;
|
|
import javax.swing.ListSelectionModel;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.event.ListSelectionEvent;
|
|
import javax.swing.event.ListSelectionListener;
|
|
import javax.swing.table.TableColumnModel;
|
|
|
|
import MEPTL.commandes;
|
|
import baseListesEtudiants.myTableBaseListesEtudiants;
|
|
import net.miginfocom.swing.MigLayout;
|
|
|
|
|
|
|
|
public class baseDonneesListesEtudiants extends JFrame{
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
private static baseDonneesListesEtudiants instance;
|
|
public static boolean isDispose = true;
|
|
private static JTable table;
|
|
private myTableBaseListesEtudiants model = new myTableBaseListesEtudiants();
|
|
private final JButton btnFermer = new JButton("<html>Femer</html>");
|
|
JScrollPane scrollPaneTable = new JScrollPane();
|
|
JScrollPane scrollPaneBoutons = new JScrollPane();
|
|
int indexSelect=0;
|
|
ListSelectionModel lsm = null;
|
|
|
|
public baseDonneesListesEtudiants() {
|
|
super();
|
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
setLocationRelativeTo( null );
|
|
setSize(1600,900);
|
|
int screenWidth = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth();
|
|
int screenHeight = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight();
|
|
setLocation(( (screenWidth) - getWidth()) / 2, (screenHeight - getHeight()) / 2);
|
|
|
|
ImageIcon img = new ImageIcon(getClass().getResource("/evalwriter.png") );
|
|
setIconImage(img.getImage());
|
|
setTitle(commandes.Titre + " - La base de données des listes des étudiants");
|
|
|
|
JPanel panelHaut = new JPanel();
|
|
getContentPane().add(panelHaut, BorderLayout.NORTH);
|
|
|
|
JLabel lblNewLabel = new JLabel("");
|
|
lblNewLabel.setIcon(new ImageIcon(baseDonneesListesEtudiants.class.getResource("/resources/accueilBaseListesEtudiants.png")));
|
|
panelHaut.add(lblNewLabel);
|
|
|
|
JPanel panelBas = new JPanel();
|
|
getContentPane().add(panelBas, BorderLayout.SOUTH);
|
|
|
|
JPanel panelGauche = new JPanel();
|
|
panelGauche.setLayout(new MigLayout("", "[:300px:400px,fill]", "[53px][][][][][][][][][30.00][20px:n][][][]"));
|
|
scrollPaneBoutons = new JScrollPane(panelGauche);
|
|
getContentPane().add(scrollPaneBoutons, BorderLayout.WEST);
|
|
|
|
|
|
model.addOrUpdate();
|
|
table = new JTable(model);
|
|
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
|
TableColumnModel columnModel = table.getColumnModel();
|
|
columnModel.getColumn(0).setPreferredWidth(300);
|
|
columnModel.getColumn(0).setMaxWidth(400);
|
|
columnModel.getColumn(1).setPreferredWidth(300);
|
|
columnModel.getColumn(1).setMaxWidth(400);
|
|
columnModel.getColumn(2).setPreferredWidth(300);
|
|
columnModel.getColumn(2).setMaxWidth(400);
|
|
|
|
table.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
|
|
|
scrollPaneTable = new JScrollPane(table);
|
|
getContentPane().add(scrollPaneTable, BorderLayout.CENTER);
|
|
|
|
//*Détection de la ligne sélectionnée
|
|
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
ListSelectionModel rowSM = table.getSelectionModel();
|
|
rowSM.addListSelectionListener(new ListSelectionListener() {
|
|
@Override
|
|
public void valueChanged(ListSelectionEvent e) {
|
|
//Ignore extra messages.
|
|
if (e.getValueIsAdjusting()) return;
|
|
lsm = (ListSelectionModel)e.getSource();
|
|
if (lsm.isSelectionEmpty()) {
|
|
System.out.println("Aucune ligne sélectionnée.");
|
|
} else {
|
|
indexSelect = lsm.getMinSelectionIndex();
|
|
System.out.println("La ligne " + indexSelect + " est sélectionnée.");
|
|
}
|
|
}
|
|
});
|
|
|
|
btnFermer.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/quitteEvaluation.png")));
|
|
btnFermer.setHorizontalAlignment(SwingConstants.LEFT);
|
|
btnFermer.setFont(new Font("Tahoma", Font.BOLD, 15));
|
|
panelGauche.add(btnFermer, "cell 0 12,growx,aligny top");
|
|
|
|
|
|
|
|
ListenerAction();
|
|
|
|
}
|
|
|
|
|
|
public static void selectRow(int indexRow) {
|
|
table.setRowSelectionInterval(indexRow, indexRow);
|
|
}
|
|
|
|
|
|
public static baseDonneesListesEtudiants getInstance() {
|
|
if (isDispose) {
|
|
instance = new baseDonneesListesEtudiants();
|
|
}
|
|
instance.setVisible(true);
|
|
isDispose=false;
|
|
return instance;
|
|
}
|
|
|
|
|
|
private void ListenerAction() {
|
|
|
|
/**
|
|
* Femer la fenêtre.
|
|
*/
|
|
btnFermer.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
isDispose=true;
|
|
dispose();
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
}
|