diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..4fc0db22080820cce251845c39eb7cb00b3bb5a7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,238 @@
+# Created by https://www.toptal.com/developers/gitignore/api/java,netbeans,maven,eclipse,intellij
+# Edit at https://www.toptal.com/developers/gitignore?templates=java,netbeans,maven,eclipse,intellij
+
+### Eclipse ###
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+.recommenders
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# PyDev specific (Python IDE for Eclipse)
+*.pydevproject
+
+# CDT-specific (C/C++ Development Tooling)
+.cproject
+
+# CDT- autotools
+.autotools
+
+# Java annotation processor (APT)
+.factorypath
+
+# PDT-specific (PHP Development Tools)
+.buildpath
+
+# sbteclipse plugin
+.target
+
+# Tern plugin
+.tern-project
+
+# TeXlipse plugin
+.texlipse
+
+# STS (Spring Tool Suite)
+.springBeans
+
+# Code Recommenders
+.recommenders/
+
+# Annotation Processing
+.apt_generated/
+.apt_generated_test/
+
+# Scala IDE specific (Scala & Java development for Eclipse)
+.cache-main
+.scala_dependencies
+.worksheet
+
+# Uncomment this line if you wish to ignore the project description file.
+# Typically, this file would be tracked if it contains build/dependency configurations:
+#.project
+
+### Eclipse Patch ###
+# Spring Boot Tooling
+.sts4-cache/
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+# .idea/artifacts
+# .idea/compiler.xml
+# .idea/jarRepositories.xml
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+# https://plugins.jetbrains.com/plugin/7973-sonarlint
+.idea/**/sonarlint/
+
+# SonarQube Plugin
+# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
+.idea/**/sonarIssues.xml
+
+# Markdown Navigator plugin
+# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
+.idea/**/markdown-navigator.xml
+.idea/**/markdown-navigator-enh.xml
+.idea/**/markdown-navigator/
+
+# Cache file creation bug
+# See https://youtrack.jetbrains.com/issue/JBR-2257
+.idea/$CACHE_FILE$
+
+# CodeStream plugin
+# https://plugins.jetbrains.com/plugin/12206-codestream
+.idea/codestream.xml
+
+# Azure Toolkit for IntelliJ plugin
+# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
+.idea/**/azureSettings.xml
+
+### Java ###
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+replay_pid*
+
+### Maven ###
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+# https://github.com/takari/maven-wrapper#usage-without-binary-jar
+.mvn/wrapper/maven-wrapper.jar
+
+# Eclipse m2e generated files
+# Eclipse Core
+.project
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+### NetBeans ###
+**/nbproject/private/
+**/nbproject/Makefile-*.mk
+**/nbproject/Package-*.bash
+build/
+nbbuild/
+dist/
+nbdist/
+.nb-gradle/
+
+# End of https://www.toptal.com/developers/gitignore/api/java,netbeans,maven,eclipse,intellij
diff --git a/pom.xml b/pom.xml
index 5cdb5d4922cbb87afba0326b5d55540a6ca86827..ffdd7d641d1b24c1dc67257171a250cd166e1a91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,6 +5,20 @@
Groupe_05
1.0-SNAPSHOT
jar
+
+
+ org.mariadb.jdbc
+ mariadb-java-client
+ 3.4.1
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.10.2
+ test
+ jar
+
+
UTF-8
17
diff --git a/src/main/java/beans/Question.java b/src/main/java/beans/Question.java
new file mode 100644
index 0000000000000000000000000000000000000000..0372ce9159201c6801785a88a5a8335accdb3ea8
--- /dev/null
+++ b/src/main/java/beans/Question.java
@@ -0,0 +1,74 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package beans;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Random;
+
+/**
+ *
+ * @author Clément GROSSELLE
+ */
+public class Question implements Serializable {
+ private int id;
+ private int level;
+ private String statement;
+ private String answer;
+
+ public Question() {
+ }
+
+ public Question(Question q) {
+ this.id = q.id;
+ this.level = q.level;
+ this.statement = q.statement;
+ this.answer = q.answer;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public void setLevel(int level) {
+ this.level = level;
+ }
+
+ public String getStatement() {
+ return statement;
+ }
+
+ public void setStatement(String statement) {
+ this.statement = statement;
+ }
+
+ public String getAnswer() {
+ return answer;
+ }
+
+ public void setAnswer(String answer) {
+ this.answer = answer;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Questions{");
+ sb.append("id=").append(id);
+ sb.append(", level=").append(level);
+ sb.append(", statement=").append(statement);
+ sb.append(", answer=").append(answer);
+ sb.append('}');
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/com/mycompany/groupe_05/Groupe_05.java b/src/main/java/com/mycompany/groupe_05/Groupe_05.java
index 585e8f53a4c05dc9284e1a22a7e60090bedd461c..2a774057185f69dc70b8cca9fb07b5f2d08a8daf 100644
--- a/src/main/java/com/mycompany/groupe_05/Groupe_05.java
+++ b/src/main/java/com/mycompany/groupe_05/Groupe_05.java
@@ -1,10 +1,8 @@
package com.mycompany.groupe_05;
-import beans.Drawing;
-
public class Groupe_05 {
public static void main(String[] args) {
- Drawing Draw = new Drawing();
}
+
}
diff --git a/src/main/java/com/mycompany/groupe_05/TestFrame.java b/src/main/java/com/mycompany/groupe_05/TestFrame.java
new file mode 100644
index 0000000000000000000000000000000000000000..caca067e5253c3bc1e9a41ea7181ac1f2f64f066
--- /dev/null
+++ b/src/main/java/com/mycompany/groupe_05/TestFrame.java
@@ -0,0 +1,32 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.mycompany.groupe_05;
+
+import gui.QuestionsGui;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+/**
+ *
+ * @author stag
+ */
+public class TestFrame extends JFrame {
+ JPanel qPane = new QuestionsGui();
+
+ public TestFrame() {
+ this.initGui();
+ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ this.setResizable(true);
+ this.pack();
+ //this.setSize(600, 600);
+ this.setLocationRelativeTo(null);
+ this.setVisible(true);
+ }
+
+ private void initGui() {
+ this.add(qPane);
+ this.setContentPane(qPane);
+ }
+}
diff --git a/src/main/java/dao/Dao.java b/src/main/java/dao/Dao.java
new file mode 100644
index 0000000000000000000000000000000000000000..1d95ae5f3ae9455fc7a4b0ad990bec81a33734d2
--- /dev/null
+++ b/src/main/java/dao/Dao.java
@@ -0,0 +1,47 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
+ */
+package dao;
+
+import java.util.Collection;
+
+/**
+ * Interface CRUD sur le stockage des données
+ * @author Clément GROSSELLE
+ * @param La classe
+ */
+public interface Dao {
+
+ /**
+ * Retourne l'objet lu en DB grâce à son identifiant ou null.
+ * @param id L'identifiant en DB de l'objet
+ * @return L'objet ou null
+ */
+ T find(int id);
+
+ /**
+ * Hydrate la DB avec l'objet fourni. Cet objet doit avoir un id null.
+ * @param obj
+ */
+ void create(T obj);
+
+ /**
+ * Supprime la ligne d'identifiant id dans la DB.
+ * @param id
+ */
+ void delete(int id);
+
+ /**
+ * Met à jour l'objet dans la DB. L'objet doit avoir un id non null.
+ * @param obj
+ */
+ void update(T obj);
+
+ /**
+ * Retourne toutes les lignes de la DB dans une collection.
+ * @return Collection contenant tous les objets hydratés par la DB.
+ */
+ Collection all();
+
+}
diff --git a/src/main/java/dao/DaoQuestion.java b/src/main/java/dao/DaoQuestion.java
new file mode 100644
index 0000000000000000000000000000000000000000..51f7d2b517c47f7da62b22b76ed0fc60b0c4f864
--- /dev/null
+++ b/src/main/java/dao/DaoQuestion.java
@@ -0,0 +1,109 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package dao;
+
+import beans.Question;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import sql.MariaDbConnection;
+
+/**
+ *
+ * @author Clément GROSSELLE
+ */
+public class DaoQuestion implements Dao {
+
+ private final Connection connect = MariaDbConnection.getInstance();
+
+ private Question createBean(ResultSet rs) {
+ Question obj = new Question();
+ try {
+ obj.setLevel(rs.getInt("level"));
+ obj.setStatement(rs.getString("statement"));
+ obj.setAnswer(rs.getString("answer"));
+ } catch (SQLException ex) {
+ System.out.println("Impossible de parcourir le resultSet" + ex.getMessage());
+ }
+ return obj;
+ }
+
+ @Override
+ public Question find(int id) {
+ Question q = null;
+ String sql = "SELECT * FROM questions WHERE id=?";
+ try (PreparedStatement pstmt = connect.prepareStatement(sql)) {
+ pstmt.setInt(1, id);
+ ResultSet rs = pstmt.executeQuery();
+ if (rs.next()) {
+ q = createBean(rs);
+ }
+ } catch (SQLException ex) {
+ throw new RuntimeException("Recherche impossible dans la table questions" + ex.getMessage());
+ }
+ return q;
+ }
+
+ @Override
+ public void create(Question obj) {
+ String sql = "INSERT INTO questions (level, statement, answer) VALUES (?, ?, ?)";
+ try (PreparedStatement pstmt = connect.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS)) {
+ pstmt.setInt(1, obj.getLevel());
+ pstmt.setString(2, obj.getStatement());
+ pstmt.setString(3, obj.getAnswer());
+ pstmt.executeUpdate();
+ ResultSet keys = pstmt.getGeneratedKeys();
+ if (keys.next()) {
+ obj.setId(keys.getInt(1));
+ }
+ } catch (SQLException ex) {
+ throw new RuntimeException("Insertion impossible dans la table questions\t Message: " + ex.getMessage());
+ }
+ }
+
+ @Override
+ public void delete(int id) {
+ String sql = "DELETE FROM questions WHERE id=?";
+ try (PreparedStatement pstmt = connect.prepareStatement(sql)) {
+ pstmt.setInt(1, id);
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ throw new RuntimeException("Suppression impossible dans la table questions" + ex.getMessage());
+ }
+ }
+
+ @Override
+ public void update(Question obj) {
+ String sql = "UPDATE questions SET level=?, statement=?, answer=? WHERE id=?";
+ try (PreparedStatement pstmt = connect.prepareStatement(sql)) {
+ pstmt.setInt(1, obj.getLevel());
+ pstmt.setString(2, obj.getStatement());
+ pstmt.setString(3, obj.getAnswer());
+ pstmt.setInt(4, obj.getId());
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ throw new RuntimeException("Update impossible dans la table questions" + ex.getMessage());
+ }
+ }
+
+ @Override
+ public Collection all() {
+ Collection list = new ArrayList<>();
+ String sql = "SELECT * FROM questions";
+ try (PreparedStatement pstmt = connect.prepareStatement(sql)) {
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ list.add(createBean(rs));
+ }
+ } catch (SQLException ex) {
+ System.out.println("Récupération impossible de la table questions" + ex.getMessage());
+ }
+ return list;
+ }
+
+}
diff --git a/src/main/java/gui/QuestionsGui.java b/src/main/java/gui/QuestionsGui.java
new file mode 100644
index 0000000000000000000000000000000000000000..00d62d90ab685eb9214dcc1b4c9045d6fbf6e9f5
--- /dev/null
+++ b/src/main/java/gui/QuestionsGui.java
@@ -0,0 +1,215 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package gui;
+
+import beans.Question;
+import dao.DaoQuestion;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.text.Normalizer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Random;
+import javax.swing.AbstractAction;
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.KeyStroke;
+
+/**
+ *
+ * @author Clément GROSSELLE
+ */
+public class QuestionsGui extends JPanel {
+
+ private static final long serialVersionUID = 1L;
+
+ JPanel questionsPane, statmentPane, helpPane, answerPane, buttonsPane;
+ JLabel sLabel, aLabel, hLabel;
+ JTextField atf;
+ JButton confirmButton, showButton, nextButton;
+ Question q = new Question();
+ Collection qlist = new ArrayList<>();
+ Font labelFont = new Font(Font.SANS_SERIF, Font.BOLD, 20);
+ Font helpFont = new Font(Font.SANS_SERIF, Font.ITALIC, 12);
+ Font buttonFont = new Font(Font.SANS_SERIF, Font.PLAIN, 15);
+ Font textFieldFont = new Font(Font.SANS_SERIF, Font.PLAIN, 20);
+
+ public QuestionsGui() {
+ qlist = initQuestion();
+ //System.out.println("qlist: " + qlist);
+ q = selectRandomQuestion((ArrayList) qlist);
+
+ // Initialisation des panneaux et composants
+ questionsPane = new JPanel();
+ statmentPane = new JPanel();
+ helpPane = new JPanel();
+ answerPane = new JPanel();
+ buttonsPane = new JPanel();
+
+ confirmButton = new JButton("Valider réponse");
+ showButton = new JButton("Afficher réponse");
+ nextButton = new JButton("Question suivante");
+
+ // Config labels:
+ // Question
+ sLabel = new JLabel("" + q.getStatement() + "");
+ sLabel.setFont(labelFont);
+ sLabel.setHorizontalAlignment(JLabel.CENTER);
+
+ // Aide
+ hLabel = new JLabel(" ", JLabel.CENTER);
+ hLabel.setFont(helpFont);
+ hLabel.setHorizontalAlignment(JLabel.CENTER);
+
+ // Réponse
+ aLabel = new JLabel("Saisissez votre réponse", JLabel.CENTER);
+ aLabel.setFont(helpFont);
+ aLabel.setHorizontalAlignment(JLabel.CENTER);
+
+ atf = new JTextField();
+
+ // Paramétrage des dfférentes font
+ confirmButton.setFont(buttonFont);
+ showButton.setFont(buttonFont);
+ nextButton.setFont(buttonFont);
+ atf.setFont(textFieldFont);
+
+ initGui();
+ initEvent();
+
+ }
+
+ private void initGui() {
+ // Layout
+ questionsPane.setLayout(new BoxLayout(questionsPane, BoxLayout.Y_AXIS));
+ answerPane.setLayout(new BoxLayout(answerPane, BoxLayout.Y_AXIS));
+
+ //Size
+ //questionsPane.setPreferredSize(new Dimension(600, 600));
+ statmentPane.setPreferredSize(new Dimension(300, 50));
+ helpPane.setPreferredSize(new Dimension(200, 50));
+ //answerPane.setPreferredSize(new Dimension(50, 20));
+ //buttonsPane.setPreferredSize(new Dimension(600, 150));
+
+ //Border
+ questionsPane.setBorder(BorderFactory.createEmptyBorder(30, 10, 10, 10));
+ //this.setBorder(BorderFactory.createLineBorder(Color.green));
+ //questionsPane.setBorder(BorderFactory.createLineBorder(Color.green));
+ //statmentPane.setBorder(BorderFactory.createLineBorder(Color.yellow));
+ //answerPane.setBorder(BorderFactory.createLineBorder(Color.green));
+ //buttonsPane.setBorder(BorderFactory.createLineBorder(Color.blue));
+
+ //Ajout des composants
+ //Question
+ statmentPane.add(sLabel);
+ //Aide
+ helpPane.add(hLabel);
+ //Saisie utilisateur
+ answerPane.add(aLabel);
+ answerPane.add(atf);
+ //Boutons
+ buttonsPane.add(confirmButton);
+ buttonsPane.add(showButton);
+ buttonsPane.add(nextButton);
+
+ // Panneau principal de l'activité
+ questionsPane.add(statmentPane);
+ questionsPane.add(helpPane);
+ questionsPane.add(answerPane);
+ questionsPane.add(buttonsPane);
+
+ // Pas sur pour ça
+ this.add(questionsPane);
+ }
+
+ private void initEvent() {
+ // Méthode validation réponse, clic confirmButton ou Enter
+ AbstractAction confirmAction = new AbstractAction() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ if (compareStrings(atf.getText(), q.getAnswer())) {
+ //Pop-up validé
+ System.out.println("oui");
+ hLabel.setText("Bravo, tu as trouvé la bonne réponse!");
+ changeQuestion();
+ atf.setText("");
+ } else {
+ System.out.println("nop");
+ hLabel.setText("Oh non c'est raté! Essaye encore.");
+ }
+ }
+ };
+ //Association au boutton confirm
+ confirmButton.addActionListener(confirmAction);
+ // Et à la touche entrée
+ atf.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "confirm");
+ atf.getActionMap().put("confirm", confirmAction);
+
+ // Clic boutton afficher réponse
+ showButton.addActionListener((ActionEvent ae) -> {
+ System.out.println("bouton afficher");
+ hLabel.setText("La réponse attendue est :\n " + q.getAnswer());
+ });
+
+ // Clic bouton suivant
+ nextButton.addActionListener((ActionEvent ae) -> {
+ hLabel.setText("");
+ System.out.println("bouton suivant\n Nombre de questions restantes:" + qlist.size());
+ if (!qlist.isEmpty()) {
+ // Si il reste des question dans la liste, on passa a la suivante
+ changeQuestion();
+ } else {
+ // Sinon on réinjecte les questions de la bdd et zérapatis
+ qlist = initQuestion();
+ changeQuestion();
+ }
+ });
+ }
+
+ private Collection initQuestion() {
+ DaoQuestion daoq = new DaoQuestion();
+ return daoq.all();
+ }
+
+ private Question selectRandomQuestion(ArrayList qlist) {
+ Random randGen = new Random();
+ //Question q = new Question();
+ int rand = randGen.nextInt(qlist.size());
+ q = qlist.get(rand);
+ try {
+ qlist.remove(rand);
+ } catch (IllegalArgumentException iae) {
+ throw new IllegalArgumentException("La liste des question est vide");
+ }
+ return q;
+ }
+
+ private String removeAccents(String text) {
+ if (text == null) {
+ return null;
+ }
+ String replaceAll = Normalizer.normalize(text, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
+ return replaceAll;
+ }
+
+ private boolean compareStrings(String inString, String ansString) {
+ inString = inString.toLowerCase();
+ ansString = ansString.toLowerCase();
+ inString = removeAccents(inString);
+ return inString.equals(ansString);
+ }
+
+ private void changeQuestion() {
+ q = selectRandomQuestion((ArrayList) qlist);
+ sLabel.setText(q.getStatement());
+ }
+
+}
diff --git a/src/main/java/sql/MariaDbConnection.java b/src/main/java/sql/MariaDbConnection.java
new file mode 100644
index 0000000000000000000000000000000000000000..736e7f2c9c033fc303a5d181d4cb3fb300e01dec
--- /dev/null
+++ b/src/main/java/sql/MariaDbConnection.java
@@ -0,0 +1,77 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package sql;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Clément GROSSELLE
+ */
+public class MariaDbConnection {
+
+ private static Connection instance;
+
+ public MariaDbConnection() {
+ }
+
+ public static Connection getInstance() throws RuntimeException {
+ if (instance == null) {
+ Properties config = getConfig();
+ try {
+ Class.forName("org.mariadb.jdbc.Driver");
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException("Driver introuvable");
+ }
+ String server = config.getProperty("server");
+ String port = config.getProperty("port");
+ String dbname = config.getProperty("dbname");
+ String url = "jdbc:mariadb://" + server + ":" + port + "/" + dbname;
+ try {
+ instance = DriverManager.getConnection(url, config);
+ } catch (SQLException ex) {
+ throw new RuntimeException("Connection à la base de donnée impossible\t Message:" + ex.getMessage());
+ }
+ }
+ return instance;
+ }
+
+ private static Properties getConfig() {
+ Properties config = new Properties();
+ try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties")) {
+ config.load(is);
+ } catch (FileNotFoundException ex) {
+ throw new RuntimeException("Fichier de paramétrage inexistant");
+ } catch (IOException ex) {
+ throw new RuntimeException("Fichier de paramétrage illisible");
+ }
+ return config;
+ }
+
+ public static void closeConnection() {
+ if (instance != null) {
+ try {
+ instance.close();
+ } catch (SQLException ex) {
+ Logger.getLogger(MariaDbConnection.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ getInstance();
+ closeConnection();
+
+ }
+
+}
diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties
new file mode 100644
index 0000000000000000000000000000000000000000..985af6abe1faa0d9b49cb1df796f025af59f9264
--- /dev/null
+++ b/src/main/resources/db.properties
@@ -0,0 +1,5 @@
+server=wp.ldnr.fr
+port=3306
+dbname=cda202401_jse_g5
+user=cda202401_jse_g5
+password=n3z3XS9y9z8jZOnB
diff --git a/src/main/resources/db.sql b/src/main/resources/db.sql
new file mode 100644
index 0000000000000000000000000000000000000000..a7ad42b41c0ffa883c499f75b3caca17bac8c1fb
--- /dev/null
+++ b/src/main/resources/db.sql
@@ -0,0 +1,77 @@
+-- phpMyAdmin SQL Dump
+-- version 4.9.6
+-- https://www.phpmyadmin.net/
+--
+-- Hôte : localhost
+-- Généré le : jeu. 19 sep. 2024 à 12:14
+-- Version du serveur : 10.1.48-MariaDB-0+deb9u2
+-- Version de PHP : 7.4.33
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET AUTOCOMMIT = 0;
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Base de données : `cda202401_jse_g5`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Structure de la table `questions`
+--
+
+CREATE TABLE `questions` (
+ `id` int(11) NOT NULL,
+ `level` int(11) NOT NULL,
+ `statement` text NOT NULL,
+ `answer` text NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+--
+-- Déchargement des données de la table `questions`
+--
+
+INSERT INTO `questions` (`id`, `level`, `statement`, `answer`) VALUES
+(1, 1, 'Combien y a-t-il de doigts sur une main?', 'Cinq'),
+(2, 1, 'De quelle couleur est le ciel?', 'Bleu'),
+(3, 1, 'De quelle couleur est le cheval blanc d\'Henry IV?', 'Blanc'),
+(4, 1, 'Quel animal fait miaou?', 'Chat'),
+(5, 1, 'De quelle couleur est une tomate bien mûre?', 'Rouge'),
+(6, 1, 'Combien y a-t-il de saisons dans une année?', 'Quatre'),
+(7, 1, 'Combien de côtés a un carré?', 'Quatre'),
+(8, 1, 'Quelle est la couleur de l\'herbe?', 'Verte'),
+(13, 1, 'Quel est le meilleur formateur?', 'Herbert'),
+(15, 1, 'Quel est le meilleur formateur?', 'Herbert');
+
+--
+-- Index pour les tables déchargées
+--
+
+--
+-- Index pour la table `questions`
+--
+ALTER TABLE `questions`
+ ADD PRIMARY KEY (`id`);
+
+--
+-- AUTO_INCREMENT pour les tables déchargées
+--
+
+--
+-- AUTO_INCREMENT pour la table `questions`
+--
+ALTER TABLE `questions`
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
diff --git a/src/test/java/dao/DaoQuestionTest.java b/src/test/java/dao/DaoQuestionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..323ee8b52510dc5c69941bd35b67a6655c7b4749
--- /dev/null
+++ b/src/test/java/dao/DaoQuestionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package dao;
+
+import beans.Question;
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
+
+/**
+ *
+ * @author CLément GROSSELLE
+ */
+public class DaoQuestionTest {
+
+ public DaoQuestionTest() {
+ }
+
+ @Test
+ public void testAllCrudMethods() {
+ DaoQuestion daoq = new DaoQuestion();
+ Question q = new Question();
+
+ System.out.println("Test de la méthode find");
+ assertDoesNotThrow(() -> daoq.find(1));
+ assertNotNull(daoq.find(1));
+ assertNull(daoq.find(0));
+
+ System.out.println("Test de la méthode create");
+ q.setStatement("test");
+ q.setAnswer("test");
+ q.setLevel(100);
+ assertDoesNotThrow(() -> daoq.create(q));
+ assertNotNull(q.getId());
+
+ System.out.println("Test de la méthode update");
+ q.setStatement("pouet");
+ q.setAnswer("pouet");
+ q.setLevel(50);
+ assertDoesNotThrow(() -> daoq.update(q));
+ assertEquals("pouet", daoq.find(q.getId()).getStatement());
+ assertEquals("pouet", daoq.find(q.getId()).getAnswer());
+ assertEquals(50, daoq.find(q.getId()).getLevel());
+
+ System.out.println("Test de la méthode delete");
+ assertDoesNotThrow(() -> daoq.delete(q.getId()));
+ assertNull(daoq.find(q.getId()));
+ }
+
+ @Test
+ public void testAll() {
+ DaoQuestion daoq =new DaoQuestion();
+ System.out.println("Test de la méthode all");
+ assertDoesNotThrow(() -> daoq.all());
+ assertEquals(daoq.all().size(), 8);
+ }
+
+}
diff --git a/target/classes/beans/Drawing$DrawArea$1.class b/target/classes/beans/Drawing$DrawArea$1.class
index aab4a789bc4bb9af8738a9261368f6a92a95c755..8010ec4c6b24722ecab7f797fdc34d6c9bd03767 100644
Binary files a/target/classes/beans/Drawing$DrawArea$1.class and b/target/classes/beans/Drawing$DrawArea$1.class differ
diff --git a/target/classes/beans/Drawing$DrawArea$2.class b/target/classes/beans/Drawing$DrawArea$2.class
index 2b7cb82cf89d26d2d7ebf92c6fcf99d32116f1b1..745683e2edc836a00c7804d82f1688bd7a4de34a 100644
Binary files a/target/classes/beans/Drawing$DrawArea$2.class and b/target/classes/beans/Drawing$DrawArea$2.class differ
diff --git a/target/classes/beans/Drawing$DrawArea.class b/target/classes/beans/Drawing$DrawArea.class
index bc680f548466c89767dc8482fb959d77c57556a6..5e2bf9fe2cd9e743b7059600e9060f33ca01913d 100644
Binary files a/target/classes/beans/Drawing$DrawArea.class and b/target/classes/beans/Drawing$DrawArea.class differ
diff --git a/target/classes/beans/Drawing.class b/target/classes/beans/Drawing.class
index 2d5c035e5297ff58be8442112dff9ea4e8db5288..8446deb921d5b3066c847610903ca43ed4a29d4f 100644
Binary files a/target/classes/beans/Drawing.class and b/target/classes/beans/Drawing.class differ
diff --git a/target/classes/com/mycompany/groupe_05/Groupe_05.class b/target/classes/com/mycompany/groupe_05/Groupe_05.class
index c9e5944b6eb377556cd6227f25cdd9a55597c646..78dca1628b6f5d3929f5e096eb60e2bce3725a62 100644
Binary files a/target/classes/com/mycompany/groupe_05/Groupe_05.class and b/target/classes/com/mycompany/groupe_05/Groupe_05.class differ
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
index a601528fe20d91b94f303b2ff1553accc802cb5b..96a1727044974c1e373f5342d3b74bc31177d696 100644
--- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -1,5 +1,15 @@
beans/Drawing$DrawArea$1.class
+com/mycompany/groupe_05/TestFrame.class
+dao/Dao.class
+beans/Drawing$DrawArea$2.class
+gui/QuestionsGui.class
beans/Drawing$DrawArea.class
+gui/QuestionsGui$1.class
+beans/Drawing$1.class
+sql/MariaDbConnection.class
+beans/Question.class
beans/Drawing.class
com/mycompany/groupe_05/Groupe_05.class
-beans/Drawing$DrawArea$2.class
+dao/DaoQuestion.class
+beans/Drawing$DrawArea$3.class
+gui/NewQuestion.class
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
index db64fcc2d3b0fa118b3b4582bdd853f37d1be886..5adef75360ee67528411fb0dbabbca57543eca81 100644
--- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -1,2 +1,9 @@
-/home/stag/Documents/07 - Java JSE/projet/Groupe_05/src/main/java/com/mycompany/groupe_05/Groupe_05.java
-/home/stag/Documents/07 - Java JSE/projet/Groupe_05/src/main/java/beans/Drawing.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/sql/MariaDbConnection.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/beans/Question.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/com/mycompany/groupe_05/TestFrame.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/dao/Dao.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/gui/NewQuestion.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/dao/DaoQuestion.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/gui/QuestionsGui.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/beans/Drawing.java
+/home/stag/NetBeansProjects/projet_java/projet_groupe05/src/main/java/com/mycompany/groupe_05/Groupe_05.java