package fr.iutfbleau.projetIHM2022FI2.Graphic; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.LinkedList; import java.util.Objects; import java.sql.Connection; import org.mariadb.jdbc.*; import java.sql.DriverManager; import java.sql.ResultSet; import javax.swing.JFrame; import javax.swing.*; import java.awt.*; import fr.iutfbleau.projetIHM2022FI2.API.Groupe; import fr.iutfbleau.projetIHM2022FI2.API.TypeGroupe; import fr.iutfbleau.projetIHM2022FI2.Graphic.View.PaintGroupe; import fr.iutfbleau.projetIHM2022FI2.MNP.GroupeNP; public class Graphic{ private PaintGroupe paint; private JFrame fenetre; LinkedList groupe; public Graphic(){ this.fenetre=new JFrame("Gestion des étudiants"); this.fenetre.setSize(1000, 720); this.fenetre.setLocation(200,200); this.fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.groupe=this.getGroupe(); this.fenetre.setVisible(true); } private LinkedList getGroupe(){ LinkedList ll= new LinkedList(); try{ Class.forName("org.mariadb.jdbc.Driver"); try{ Connection cnx = DriverManager.getConnection( "jdbc:mariadb://dwarves.iut-fbleau.fr/chaignea", "chaignea", "Chaigneauphpmyadmin"); try{ PreparedStatement pst = cnx.prepareStatement( "SELECT * FROM `Groupe` GROUP BY `id` ORDER BY `id` ASC;"); try{ ResultSet rs = pst.executeQuery(); try{ while(rs.next()){ //valeur sentinel pour pas de groupe parent : -1 if(rs.getInt(6)!=-1){ ll.add(new GroupeNP(rs.getInt(0), rs.getString(1), rs.getInt(2), rs.getInt(3), TypeGroupe.getType(rs.getString(4)), ll.get(rs.getInt(6)))); }else{ ll.add(new GroupeNP(rs.getInt(0), rs.getString(1), rs.getInt(2), rs.getInt(3), TypeGroupe.getType(rs.getString(4)), null)); } } }catch(SQLException e){ System.out.println("erreur dans la prise de resultat"); } rs.close(); }catch(SQLException e){ System.out.println("erreur dans le resultat"); } pst.close(); }catch(SQLException e){ System.out.println("erreur dans la preparation"); } cnx.close(); }catch(SQLException e){ System.out.println("Erreur dans la connexion!"); } }catch(ClassNotFoundException e){ System.out.println("pilote non disponible"); } return ll; } }