实现所有界面与功能1.0

pull/2/head
陈映江 5 months ago
parent 92c63026ee
commit 3bb158eccd

@ -5,5 +5,5 @@
"registrationDate" : [ 2025, 10, 10, 11, 7, 5, 853200500 ],
"verificationCode" : "688201",
"verified" : true,
"type" : "小学"
"type" : "初中"
} ]

@ -13,7 +13,7 @@ public class SelTestFrame extends JFrame {
private int questionNum;
private int currentQuestionDex;
private String[] answers;
private String[] myAnswers;
private JLabel titleLabel;
private JButton optionA;
@ -30,7 +30,7 @@ public class SelTestFrame extends JFrame {
this.userService = userService;
this.questionNum = num;
this.currentQuestionDex = 0;
this.answers = new String[questionNum];
this.myAnswers = new String[questionNum];
InitUI();
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
@ -158,19 +158,19 @@ public class SelTestFrame extends JFrame {
switch (answer) {
case "A":
optionA.setBackground(Color.GREEN);
answers[currentQuestionDex] = answer;
myAnswers[currentQuestionDex] = answer;
break;
case "B":
optionB.setBackground(Color.GREEN);
answers[currentQuestionDex] = answer;
myAnswers[currentQuestionDex] = answer;
break;
case "C":
optionC.setBackground(Color.GREEN);
answers[currentQuestionDex] = answer;
myAnswers[currentQuestionDex] = answer;
break;
case "D":
optionD.setBackground(Color.GREEN);
answers[currentQuestionDex] = answer;
myAnswers[currentQuestionDex] = answer;
break;
}
@ -187,11 +187,11 @@ public class SelTestFrame extends JFrame {
if (currentQuestionDex > 0) {
currentQuestionDex--;
updateTitleLabel();
if (answers[currentQuestionDex] == null) {
if (myAnswers[currentQuestionDex] == null) {
resetButtonColors();
}
else {
saveAnswer(answers[currentQuestionDex]);
saveAnswer(myAnswers[currentQuestionDex]);
}
updateNavigationButtons();
@ -202,10 +202,10 @@ public class SelTestFrame extends JFrame {
if (currentQuestionDex < questionNum - 1) {
currentQuestionDex++;
updateTitleLabel();
if (answers[currentQuestionDex] == null) {
if (myAnswers[currentQuestionDex] == null) {
resetButtonColors();
} else {
saveAnswer(answers[currentQuestionDex]);
saveAnswer(myAnswers[currentQuestionDex]);
}
updateNavigationButtons();
@ -215,13 +215,16 @@ public class SelTestFrame extends JFrame {
private void goToSubmit() {
int confirm = JOptionPane.showConfirmDialog(SelTestFrame.this, "你确定要提交试卷吗?", "提示", JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
int score = 0;
int correctCount = 0;
double accuracy = Math.round((double) correctCount / myAnswers.length * 10000) / 100.0;
double score = Math.round((double) correctCount * 100 / myAnswers.length * 10) / 10.0;
// 弹出分数结果
String[] options = {"返回主菜单", "继续做题"};
int choice = JOptionPane.showOptionDialog(
SelTestFrame.this,
"您的得分是: " + score + "分",
"您答对了" + score + "道题,正确率为" + String.format("%.2f", accuracy) + "\n您的得分是: " + score + "分",
"测试结果",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
@ -275,4 +278,17 @@ public class SelTestFrame extends JFrame {
dispose();
}
}
private int getScore(String[] answers, String[] myAnswers) {
if (answers == null || myAnswers == null){
return 0;
}
int score = 0;
for (int i = 0; i < answers.length; i++) {
if (answers[i] != null && answers[i].equals(myAnswers[i])){
score++;
}
}
return score;
}
}

Loading…
Cancel
Save