debut MPD

This commit is contained in:
2022-11-12 19:19:37 +01:00
parent fcf32a2ec0
commit 6c20bfcdf2
8 changed files with 145 additions and 55 deletions

View File

@@ -0,0 +1,74 @@
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> 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<Groupe> getGroupe(){
LinkedList<Groupe> ll= new LinkedList<Groupe>();
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;
}
}

View File

@@ -1,42 +0,0 @@
package fr.iutfbleau.projetIHM2022FI2.Graphic.View;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import fr.iutfbleau.projetIHM2022FI2.API.Groupe;
import fr.iutfbleau.projetIHM2022FI2.Graphic.Controller.ObservateurFenetre;
public class MaFenetre extends JFrame{
private JPanel Left;
private JPanel Right;
private PaintGroupe paint;
public MaFenetre(){
super();
this.setSize(1000,720);
this.setLocation(200,200);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new ObservateurFenetre());
this.setLayout(new GridLayout(1,2));
this.Left=new JPanel(new GridLayout(2,1));
this.Right=new JPanel();
this.paint=new PaintGroupe();
this.Left.setBackground(Color.RED);
this.Left.add(this.paint);
this.add(this.Left);
this.Right.setBackground(Color.BLUE);
this.add(this.Right);
}
public void addGroupe(Groupe g){
this.paint.addGroupe(g);
}
}

View File

@@ -26,10 +26,11 @@ public class PaintGroupe extends JComponent {
int y=100;
for(Groupe g: this.tabGroupe){
secondPinceau.setColor(Color.BLACK);
secondPinceau.setFont(new Font(Font.SANS_SERIF, Font.BOLD, this.getWidth()/10));
secondPinceau.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 40));
FontMetrics metrics = secondPinceau.getFontMetrics(secondPinceau.getFont());
secondPinceau.drawString(g.getName().toUpperCase(), (this.getWidth()/2-metrics.stringWidth(g.getName().toUpperCase())/2), (y-metrics.getAscent()));
g.getName();
y+=100;
}
}