-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQcmFrame.java
More file actions
133 lines (109 loc) · 3.98 KB
/
QcmFrame.java
File metadata and controls
133 lines (109 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.* ;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
/**
*
* @author Salahdine Ouhmmiali v 1.0
*
*/
/* Construire la frame pour les qcm */
public class QcmFrame extends JPanel {
JLabel Q;
JButton option1 ,
option2,
option3,
option4 ;
String reponse_correcte;
static boolean next = false ;
static int score = 0 ;
static JLabel timer = new JLabel ("00 : 00 : 000") ;
static Compteur count = new Compteur ();
/* Constructeur de la frame QcmFrame */
QcmFrame (Qcm obj , JFrame window) {
Q = new JLabel (obj.question); // La question
option1 = new JButton (obj.option1) ; // les choix
option2 = new JButton (obj.option2) ;
option3 = new JButton (obj.option3) ;
option4 = new JButton (obj.option4) ;
reponse_correcte = obj.reponse_correcte ; // la réponse correcte
JPanel pan = new JPanel () ;
pan.setLayout(null);
pan.setBorder(BorderFactory.createLineBorder(Color.gray));
pan.setBackground(Color.DARK_GRAY);
window.setContentPane(pan);
setLayout(null);
setBackground(Color.getHSBColor(154, 254, 25));
setBounds(100,90,600,300);
setBorder(BorderFactory.createLineBorder(Color.black));
pan.add(this);
add(Q); add(option1); add(option2); add(option3); add(option4);
Q.setBounds(40,8,520,150);
Q.setBorder(new LineBorder(Color.blue, 2, true));
Q.setHorizontalAlignment(JLabel.CENTER);
option1.setBounds(80,180,200,40); option1.setBackground(new Color(255,255,255)) ;
option2.setBounds(80,240,200,40); option2.setBackground(new Color(255,255,255)) ;
option3.setBounds(320,180,200,40); option3.setBackground(new Color(255,255,255)) ;
option4.setBounds(320,240,200,40); option4.setBackground(new Color(255,255,255)) ;
option1.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
option2.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
option3.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
option4.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
timer.setBounds(250,420,300,30);
timer.setFont(new Font("Verdana", Font.BOLD, 40));
timer.setHorizontalAlignment(JLabel.CENTER);
timer.setBorder(BorderFactory.createLineBorder(Color.white));
timer.setForeground(Color.white);
pan.add(timer);
window.setVisible(true);
}
/*Valider la réponse de l'utilisateur */
void getAnswer (int time) throws InterruptedException {
option1.addActionListener((ActionEvent e) -> {
if (option1.getText().equals(reponse_correcte)) score++ ;
next = true ;
});
option2.addActionListener((ActionEvent e) -> {
if (option2.getText().equals(reponse_correcte)) score++ ;
next = true ;
});
option3.addActionListener((ActionEvent e) -> {
if (option3.getText().equals(reponse_correcte)) score++ ;
next = true ;
});
option4.addActionListener((ActionEvent e) -> {
if (option4.getText().equals(reponse_correcte)) score++ ;
next = true ;
});
while (next == false ) {
timer.setText(String.format("%02d", count.M)+" : "+String.format("%02d", count.S)+" : "+String.format("%03d", count.Ms));
count.Ms++ ;
Thread.sleep(1);
if (count.Ms==999){
count.S++ ;
count.Ms=0 ;
}
if (count.S==59){
count.M++ ;
count.S=0;
}
if ((count.S + count.M*60) > time-3 ) {
timer.setForeground(Color.red);
if ((count.S + count.M*60)==time) {
return ;
}
}
}
next = false ;
}
/* Obtenir le score du test */
int getScore() {return score ;}
Compteur getTime () {return count ;}
void Reset () {
count.M=0 ;
count.Ms=0 ;
count.S=0;
score = 0 ;
}
}