some changes

This commit is contained in:
2025-10-02 10:48:05 +02:00
parent 8b6d447574
commit 6ceeffac0e
14 changed files with 342 additions and 48 deletions

View File

@@ -0,0 +1,86 @@
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
public class GridWindow extends JFrame {
public GridWindow() {
this.setSize(200, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.getContentPane().setLayout(new GridBagLayout());
this.placeButtons();
this.addWindowListener(new GridWindowClosedEvent(this));
}
private void placeButtons() {
GridBagConstraints constraints = new GridBagConstraints();
JButton one = new JButton("1");
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(0, 0, 0, 0);
constraints.weightx = 1.0;
constraints.weighty = 1.0;
this.getContentPane().add(one, constraints);
JButton two = new JButton("2");
constraints.gridx = 2;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 2;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(0, 0, 0, 0);
constraints.weightx = 1.0;
constraints.weighty = 1.0;
this.getContentPane().add(two, constraints);
JButton three = new JButton("3");
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(0, 0, 0, 0);
constraints.weightx = 1.0;
constraints.weighty = 1.0;
this.getContentPane().add(three, constraints);
JButton four = new JButton("4");
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 2;
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = new Insets(0, 0, 0, 0);
constraints.weightx = 1.0;
constraints.weighty = 1.0;
this.getContentPane().add(four, constraints);
JButton five = new JButton("5");
constraints.gridx = 1;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.fill = GridBagConstraints.NONE;
constraints.insets = new Insets(0, 0, 0, 0);
constraints.weightx = 0.0;
constraints.weighty = 0.0;
this.getContentPane().add(five, constraints);
}
}

View File

@@ -0,0 +1,19 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
public class GridWindowClosedEvent extends WindowAdapter {
private GridWindow window;
public GridWindowClosedEvent(GridWindow window) {
this.window = window;
}
@Override
public void windowClosing(WindowEvent event) {
int result = JOptionPane.showConfirmDialog(this.window, "Are you sure you want to close this window?", "Close current window", JOptionPane.YES_NO_OPTION);
if(result == JOptionPane.YES_OPTION) this.window.dispose();
}
}

View File

@@ -0,0 +1,7 @@
public class Main {
public static void main(String[] args) {
GridWindow window = new GridWindow();
window.setVisible(true);
}
}

View File

@@ -0,0 +1,18 @@
public class Champ {
private String code;
private String[] modules;
public Champ(String code, String[] modules) {
this.code = code;
this.modules = modules;
}
public String getCode() {
return this.code;
}
public String[] getModules() {
return this.modules;
}
}

View File

@@ -0,0 +1,44 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class Database {
private Connection connection;
public Database() {
try {
Class.forName("org.mariadb.jdbc.Driver");
this.connection = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/baudrier",
"baudrier",
"baudrier"
);
} catch(ClassNotFoundException exception) {
System.err.println("Class 'org.mariadb.jdbc.Driver' not found.");
} catch(SQLException exception) {
System.err.println("Error while trying to connect to the database");
}
}
public Champ[] getAllData() {
PreparedStatement query = this.connection.prepareStatement("SELECT id, code FROM Champ");
ResultSet result = query.executeQuery();
while(result.next()) {
query = this.connection.prepareStatement("SELECT code FROM Modules WHERE champId = " + result.getInt("id"));
}
}
public void close() {
try {
this.connection.close();
} catch(SQLException exception) {
System.err.println("Error while trying to close the connection.");
}
}
}

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,21 @@
CREATE TABLE Champ (
id INT PRIMARY KEY AUTO_INCREMENT,
code VARCHAR(20)
);
CREATE TABLE Module (
id INT PRIMARY KEY AUTO_INCREMENT,
champId INT REFERENCES Champ(id),
code VARCHAR(20)
);
INSERT INTO Champ(code) VALUES ("APL");
INSERT INTO Champ(code) VALUES ("WIM");
INSERT INTO Module(champId, code) VALUES (1, "M1102");
INSERT INTO Module(champId, code) VALUES (1, "M1103");
INSERT INTO Module(champId, code) VALUES (1, "M3103");
INSERT INTO Module(champId, code) VALUES (2, "M1105");
INSERT INTO Module(champId, code) VALUES (2, "M3104");
INSERT INTO Module(champId, code) VALUES (2, "M4103C");
INSERT INTO Module(champId, code) VALUES (2, "M4104C");