-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQrcFrame.java
More file actions
115 lines (97 loc) · 3.63 KB
/
QrcFrame.java
File metadata and controls
115 lines (97 loc) · 3.63 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
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
/*
Frame pour les questions à réponse courtes
*/
public class QrcFrame extends JPanel {
String reponse_correcte;
JLabel questionLabel,
yourAnswer;
JTextField answer;
JButton valider;
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 */
QrcFrame(Qrc obj, JFrame window){
questionLabel = new JLabel (obj.question);
reponse_correcte = obj.reponse;
valider = new JButton("Valider");
yourAnswer = new JLabel("Réponse :");
answer = new JTextField(20);
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(questionLabel); add(answer); add(yourAnswer); add(valider);
questionLabel.setBounds(40,8,520,150);
questionLabel.setBorder(new LineBorder(Color.blue, 2, true));
questionLabel.setHorizontalAlignment(JLabel.CENTER);
yourAnswer.setBounds(80,180,100,40);
yourAnswer.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
answer.setBounds(200,180,200,40);
answer.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
valider.setBounds(160,240,100,40);
valider.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 {
valider.addActionListener((ActionEvent e) -> {
if (answer.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 */
int getScore() {return score ;}
Compteur getTime () {return count ;}
/* Réinitialiser les paramètres du test */
void Reset () {
count.M=0 ;
count.Ms=0 ;
count.S=0;
score = 0 ;
}
}