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