Skip to content

Commit

Permalink
tested EtudiantDao and added events listenner
Browse files Browse the repository at this point in the history
  • Loading branch information
saaya-code committed Mar 24, 2024
1 parent f628c7d commit 4a3a790
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/ExercicesTP/CRUD/EtudiantDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

import java.sql.*;


// TODO: Test this class
public class EtudiantDAO implements EtudiantDaoCRUD{


Connection con = null;
Statement st = null;
public EtudiantDAO() {
Expand Down
38 changes: 35 additions & 3 deletions src/ExercicesTP/IHM/IHMAjoutEtudiant.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package ExercicesTP.IHM;
import ExercicesTP.CRUD.EtudiantDAO;
import ExercicesTP.Etudiant;

import javax.swing.*;
import java.awt.*;

Expand All @@ -7,15 +10,16 @@ public class IHMAjoutEtudiant extends JInternalFrame{
public JTextField nomField, prenomField, numEtdField;
public JComboBox<String> filiereComboBox;
public JComboBox<Integer> niveauComboBox, groupeComboBox;

public EtudiantDAO dao;
public JButton addButton, cancelButton;
public IHMAjoutEtudiant(){
public IHMAjoutEtudiant(EtudiantDAO dao){
setTitle("Ajout d'un étudiant");
setSize(400, 400);
initializeComponents();
createLayout();
//addEventListeners();
addEventListeners();
setVisible(true);
this.dao = dao;
}
private void addComponent(JPanel panel, JComponent component, GridBagConstraints c, int x, int y, int width, int height) {
c.gridx = x;
Expand Down Expand Up @@ -68,5 +72,33 @@ public void createLayout() {
addComponent(panel, cancelButton, c, 1, 6, 1, 1);
add(panel);
}
public void emptyForm(){
nomField.setText("");
prenomField.setText("");
numEtdField.setText("");
filiereComboBox.setSelectedIndex(0);
niveauComboBox.setSelectedIndex(0);
groupeComboBox.setSelectedIndex(0);
}
public void addEventListeners(){
addButton.addActionListener((e)->{
// Get the values from the form
String nom = nomField.getText();
String prenom = prenomField.getText();
int numEtd = Integer.parseInt(numEtdField.getText());
String filiere = (String) filiereComboBox.getSelectedItem();
int niveau = (int) niveauComboBox.getSelectedItem();
int groupe = (int) groupeComboBox.getSelectedItem();
Etudiant etudiant = new Etudiant(numEtd, nom, prenom, filiere, niveau, groupe);
dao.addEtudiant(etudiant);
JOptionPane.showMessageDialog(this, "Etudiant ajouté avec succès");
emptyForm();
});

cancelButton.addActionListener((e)->{
emptyForm();
dispose();
});
}

}
6 changes: 5 additions & 1 deletion src/ExercicesTP/IHM/Principale.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ExercicesTP.IHM;

import ExercicesTP.CRUD.EtudiantDAO;
import ExercicesTP.CRUD.FormationDAO;
import ExercicesTP.Etudiant;
import TP_Base.Config;
import TP_Base.MyConnexion;

Expand Down Expand Up @@ -29,6 +31,7 @@ public class Principale extends JFrame {
JMenuItem menuItemAfficherFormation;
JDesktopPane desktop;
FormationDAO formationDao;
EtudiantDAO etudiantDAO;
Principale() {
menuBar = new JMenuBar();
this.setTitle("Gestion des formation");
Expand Down Expand Up @@ -73,6 +76,7 @@ public class Principale extends JFrame {
this.setJMenuBar(menuBar);
this.setVisible(true);
formationDao = new FormationDAO();
etudiantDAO = new EtudiantDAO();
// listenners
menuItemAjouteurFormation.addActionListener(new ActionListener() {
@Override
Expand Down Expand Up @@ -100,7 +104,7 @@ public void actionPerformed(ActionEvent e) {
menuItemAjouteurEtudiant.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
IHMAjoutEtudiant ihmAjoutEtud = new IHMAjoutEtudiant();
IHMAjoutEtudiant ihmAjoutEtud = new IHMAjoutEtudiant(etudiantDAO);
desktop.add(ihmAjoutEtud);
}
});
Expand Down

0 comments on commit 4a3a790

Please sign in to comment.