Skip to content
......@@ -16,7 +16,6 @@ public class CalculWindow {
private final JButton btnVerify, btnSolution, btnNewCalcul;
private int resultat;
// CONSTRUCTOR -------------------------------------------------------------
public CalculWindow() {
//GUI ITEMS CREATION
......@@ -33,7 +32,6 @@ public class CalculWindow {
initEvents();
generateCalcul();
}
private void initGui() {
//INTERFACE MANAGEMENT -------------------------------------------------
calculPanel.setLayout(new BoxLayout(calculPanel, BoxLayout.Y_AXIS));
......@@ -50,7 +48,6 @@ public class CalculWindow {
group2Panel.add(btnSolution);
group2Panel.add(btnNewCalcul);
}
// EVENTS MANAGEMENT -------------------------------------------------------
private void initEvents() {
btnVerify.addActionListener(new ActionListener() {
......@@ -74,7 +71,6 @@ public class CalculWindow {
}
});
}
// CALCULATION MANAGEMENT --------------------------------------------------
private void generateCalcul() {
// SELECT RANDOM NUMBERS
......@@ -93,7 +89,6 @@ public class CalculWindow {
txtAnswer.setText("");
}
// VERIFY AND EXCEPTIONS MANAGEMENT -----------------------------------------
private void verifyAnswer() {
try {
......@@ -107,7 +102,6 @@ public class CalculWindow {
JOptionPane.showMessageDialog(calculPanel, "Veuillez entrer un nombre valide.");
}
}
public JPanel getPanel() {
return calculPanel;
}
......
......@@ -38,7 +38,6 @@ public class DrawWindow {
initGui();
initEvents();
}
private void initGui() {
// POSITION MANAGEMENT
drawPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
......@@ -52,7 +51,6 @@ public class DrawWindow {
btnGroup.add(btnBlueColor);
btnGroup.add(btnRedColor);
}
// EVENTS MANAGEMENT
private void initEvents() {
// HERBERT'S CODE
......@@ -81,13 +79,10 @@ public class DrawWindow {
btnBlueColor.addActionListener(e -> currentColor = Color.BLUE);
btnRedColor.addActionListener(e -> currentColor = Color.RED);
}
public JPanel getPanel() {
return container;
}
private void resetDrawPanel() {
drawPanel.repaint(); // CLEAN SCREEN
}
}
......@@ -18,9 +18,7 @@ import javax.swing.JPanel;
public class MainWindow extends JFrame {
//Creation of an activity array to manage the panels
//index 0: Drawing panel
//index 1: Calcul panel
//index 2: Questions and Answers panel"
//index 0: Drawing panel, index 1: Calcul panel, index 2: Questions and Answers panel
private final JPanel[] activities = new JPanel[3];
private final JPanel mainPanel;
private final JMenuBar menuBar;
......@@ -49,7 +47,6 @@ public class MainWindow extends JFrame {
setJMenuBar(menuBar);
setVisible(true);
}
private void initGui() {
mainPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
menuBar.setPreferredSize(new Dimension(800, 40));
......@@ -59,7 +56,6 @@ public class MainWindow extends JFrame {
menuBar.add(menuActivities); // Ajout du menu Activités
menuBar.add(menuQuit);
}
// ACTIVITIES INITIALISATION -----------------------------------------------
private void initActivities() {
//Store each panel in the activity list
......@@ -67,7 +63,6 @@ public class MainWindow extends JFrame {
activities[1] = new CalculWindow().getPanel();
activities[2] = new QuestionWindow().getPanel();
}
private void initEvents() {
menuItemDrawing.addActionListener(new ActionListener() {
@Override
......@@ -97,7 +92,6 @@ public class MainWindow extends JFrame {
}
});
}
private void changeActivity(int index) {
//Switch from one panel to another by navigating through the array using the index
mainPanel.removeAll();
......
......@@ -3,6 +3,7 @@ package groupe3.jeux_enfants;
import beans.Question;
import DAO.DaoQuestion;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
......@@ -10,12 +11,15 @@ import java.text.Normalizer;
import java.util.Collection;
import java.util.Random;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
/**
*
......@@ -24,13 +28,16 @@ import javax.swing.JTextField;
public class QuestionWindow {
private final DaoQuestion daoQuestion;
private int selectedLevel = 1;
private int lastQuestionId = -1;
private String resultat;
private final JPanel questionPanel;
private final JPanel headerPanel;
private final JLabel titre;
private final JRadioButton niveau1, niveau2, niveau3;
private final JTextArea txtQuestion;
private JTextField txtAnswer;
private final JTextField txtAnswer;
private final JButton btnVerify, btnReponse, btnNewQuestion;
//Constructeur
......@@ -39,7 +46,17 @@ public class QuestionWindow {
questionPanel = new JPanel();
questionPanel.setLayout(new GridLayout(6, 0));
headerPanel = new JPanel();
headerPanel.setLayout(new FlowLayout());
titre = new JLabel("Questions-réponses :");
niveau1 = new JRadioButton("Niveau 1");
niveau1.setSelected(true);
niveau2 = new JRadioButton("Niveau 2");
niveau3 = new JRadioButton("Niveau 3");
ButtonGroup civil = new ButtonGroup();
civil.add(niveau1);
civil.add(niveau2);
civil.add(niveau3);
txtQuestion = new JTextArea("[QUESTION PLACEHOLDER]");
txtQuestion.setLineWrap(true);
......@@ -47,7 +64,7 @@ public class QuestionWindow {
txtQuestion.setEditable(false);
txtQuestion.setPreferredSize(new Dimension(300, 75));
txtQuestion.setMaximumSize(new Dimension(300, 75));
// Optionnel : ajout de marges pour le confort
//Ajout de marges pour distinction avec l'autre zone de text
txtQuestion.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
txtAnswer = new JTextField();
......@@ -61,7 +78,11 @@ public class QuestionWindow {
daoQuestion = new DaoQuestion();
//Ajout de tout les éléments au panel
questionPanel.add(titre);
questionPanel.add(headerPanel);
headerPanel.add(titre);
headerPanel.add(niveau1);
headerPanel.add(niveau2);
headerPanel.add(niveau3);
questionPanel.add(txtQuestion);
questionPanel.add(txtAnswer);
questionPanel.add(btnVerify);
......@@ -70,7 +91,57 @@ public class QuestionWindow {
generateQuestion();
txtAnswer.addAncestorListener(new javax.swing.event.AncestorListener() {
@Override
public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
//Donne le focus au champ txtAnswer quand le panneau apparait
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
txtAnswer.requestFocusInWindow();
}
});
}
@Override
public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
//Rien à mettre ici
}
@Override
public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
//Non plus
}
});
//Gestion des évènements
niveau1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedLevel = 1; //Définit le niveau à 1
generateQuestion(); //Recharge la question
txtAnswer.setText("");//Remet la zone de réponse à zero
}
});
niveau2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedLevel = 2;
generateQuestion();
txtAnswer.setText("");
}
});
niveau3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedLevel = 3;
generateQuestion();
txtAnswer.setText("");
}
});
btnVerify.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -96,7 +167,7 @@ public class QuestionWindow {
private void generateQuestion() {
// Récupère toutes les questions de niveau 1
Collection<Question> questions = daoQuestion.findByLevel(1);
Collection<Question> questions = daoQuestion.findByLevel(selectedLevel);
if (questions != null && !questions.isEmpty()) {
// Convertit la collection en tableau pour faciliter la sélection aléatoire
......@@ -119,7 +190,7 @@ public class QuestionWindow {
// Sauvegarde la réponse correcte pour une vérification ultérieure
resultat = randomQuestion.getAnswer();
} else {
txtQuestion.setText("Aucune question trouvée pour le niveau 1 !");
txtQuestion.setText("Aucune question trouvée pour le niveau " + selectedLevel + " !");
}
}
......
......@@ -7,9 +7,9 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Classe implémentant le pattern singleton pour la connexion à la DB.
*
*
* @author Herbert Caffarel
* @author
*/
public final class MariaDbConnection {
......@@ -20,8 +20,7 @@ public final class MariaDbConnection {
public static Connection getInstance() throws RuntimeException {
if (instance == null) {
// La connexion n'existe pas encore, je la crée
try { // charger le driver. Inutile en principe...
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException ex) {
throw new RuntimeException("Driver introuvable");
......