This commit is contained in:
Simoes Lukas
2025-09-24 16:24:52 +02:00
parent 2c3e150ec5
commit 3b7b5533c1
31 changed files with 355 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,114 @@
import org.mariadb.jdbc.*;
import java.awt.*;
import java.sql.*;
public class Donnees {
private String[] modules;
private String[] champs;
private int[] idChamps;
public Donnees() {
// FAIRE UN TABLEAU PAR TABLE DE LA BASE DE DONNEES AU LIEU DE RASSEMBLER LES DEUX
try {
Connection cnx = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/simoes",
"simoes", "simoes"
);
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException e2) {
System.err.println("Problème de pilote.");
}
try {
// QUERY 1
PreparedStatement pst = cnx.prepareStatement(
"SELECT * FROM module;"
);
ResultSet rs = pst.executeQuery();
rs.last();
this.modules = new String[rs.getInt(1)];
rs.first();
int i = 0;
this.modules[i] = rs.getString(2);
while (rs.next()) {
i++;
this.modules[i] = rs.getString(2);
}
rs.close();
pst.close();
// QUERY 2
PreparedStatement pst2 = cnx.prepareStatement(
"SELECT COUNT(*) FROM champ;"
);
ResultSet rs2 = pst2.executeQuery();
rs2.last();
this.idChamps = new int[rs2.getInt(1)];
this.champs = new String[rs2.getInt(1)];
rs2.close();
pst2.close();
// QUERY 3
PreparedStatement pst3 = cnx.prepareStatement(
"SELECT * FROM champ;"
);
ResultSet rs3 = pst3.executeQuery();
i = 0;
while (rs3.next()) {
this.idChamps[i] = rs3.getInt(1);
this.champs[i] = rs3.getString(2);
i++;
}
for (i = 0; i != this.champs.length; i++) {
System.out.println(this.idChamps[i] + " | " + this.champs[i]);
}
rs3.close();
pst3.close();
// TODO
} catch (SQLException e3) {
System.err.println("Erreur de syntaxe SQL.");
}
cnx.close();
} catch (SQLException e1) {
System.err.println("Erreur de connexion à la base de données.");
}
}
public String[] getModules() {
return this.modules;
}
public int[] getIdChamps() {
return this.idChamps;
}
public String[] getChamps() {
return this.champs;
}
}

Binary file not shown.

View File

@@ -0,0 +1,77 @@
import java.awt.*;
import javax.swing.*;
import java.util.Arrays;
public class Fenetre extends JFrame {
private String[] modules;
private String[] champs;
private int[] idChamps;
public Fenetre(String[] modules, String[] champs, int[] idChamps) {
this.modules = modules;
this.champs = champs;
this.idChamps = idChamps;
int[] nbChampsParModule = new int[this.modules.length];
Arrays.fill(nbChampsParModule, 0);
int indexIdChamps = 0;
for (int i = 0; i != this.modules.length; i++) {
while ((indexIdChamps < this.idChamps.length) && this.idChamps[indexIdChamps] == (i+1)) {
nbChampsParModule[i]++;
indexIdChamps++;
}
System.out.println(nbChampsParModule[i]);
}
System.out.println(Arrays.toString(nbChampsParModule));
this.setSize(200, 500);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH; // Make the component fill its display area entirely
gbc.gridwidth = 1;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
for (int i = 0; i != this.modules.length; i++) {
gbc.gridheight = nbChampsParModule[i];
JLabel texte = new JLabel(this.modules[i]);
texte.setBorder(BorderFactory.createLineBorder(Color.BLACK));
texte.setHorizontalAlignment(JLabel.CENTER);
texte.setVerticalAlignment(JLabel.CENTER);
this.add(texte, gbc);
gbc.gridy += nbChampsParModule[i];
}
gbc.gridx = 1;
gbc.gridheight = 1;
for (int i = 0; i != this.champs.length; i++) {
gbc.gridy = i;
JLabel texte = new JLabel(this.champs[i]);
texte.setBorder(BorderFactory.createLineBorder(Color.BLACK));
texte.setHorizontalAlignment(JLabel.CENTER);
texte.setVerticalAlignment(JLabel.CENTER);
this.add(texte, gbc);
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
public class Main {
public static void main(String[] args) {
Donnees donnees = new Donnees();
Fenetre fenetre = new Fenetre(donnees.getModules(), donnees.getChamps(), donnees.getIdChamps());
fenetre.setVisible(true);
}
}