|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package mathlearning.ui;
|
|
|
|
|
|
|
|
|
|
import mathlearning.model.User;
|
|
|
|
|
import mathlearning.service.MultipleChoiceGenerator.MultipleChoiceGenerator;
|
|
|
|
|
import mathlearning.service.UserService;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
@ -10,9 +11,11 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
private MainFrame mainFrame;
|
|
|
|
|
private User user;
|
|
|
|
|
private UserService userService;
|
|
|
|
|
private MultipleChoiceGenerator multipleChoiceGenerator;
|
|
|
|
|
|
|
|
|
|
private int questionNum;
|
|
|
|
|
private int currentQuestionDex;
|
|
|
|
|
private String[] answers;
|
|
|
|
|
private String[] myAnswers;
|
|
|
|
|
|
|
|
|
|
private JLabel titleLabel;
|
|
|
|
|
@ -23,6 +26,8 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
private JButton prevButton;
|
|
|
|
|
private JButton nextButton;
|
|
|
|
|
private JButton submitButton;
|
|
|
|
|
private JLabel question;
|
|
|
|
|
private JLabel choice;
|
|
|
|
|
|
|
|
|
|
public SelTestFrame(MainFrame mainFrame, User user, UserService userService, int num) {
|
|
|
|
|
this.mainFrame = mainFrame;
|
|
|
|
|
@ -31,6 +36,8 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
this.questionNum = num;
|
|
|
|
|
this.currentQuestionDex = 0;
|
|
|
|
|
this.myAnswers = new String[questionNum];
|
|
|
|
|
this.multipleChoiceGenerator = new MultipleChoiceGenerator(num, user);
|
|
|
|
|
this.answers = multipleChoiceGenerator.GetCorrectAnswerNo();
|
|
|
|
|
InitUI();
|
|
|
|
|
addWindowListener(new java.awt.event.WindowAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
@ -95,7 +102,21 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JPanel centerPanel() {
|
|
|
|
|
JPanel panel = new JPanel(new BorderLayout());
|
|
|
|
|
JPanel panel = new JPanel(new GridLayout(6, 1));
|
|
|
|
|
|
|
|
|
|
JLabel questionLabel = new JLabel("题目:");
|
|
|
|
|
questionLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
question = new JLabel(multipleChoiceGenerator.GetQuestionList()[currentQuestionDex]);
|
|
|
|
|
question.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
panel.add(questionLabel);
|
|
|
|
|
panel.add(question);
|
|
|
|
|
|
|
|
|
|
JLabel choiceLabel = new JLabel("选项:");
|
|
|
|
|
choiceLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
choice = new JLabel(multipleChoiceGenerator.GetChoiceList()[currentQuestionDex]);
|
|
|
|
|
choiceLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
|
|
panel.add(choiceLabel);
|
|
|
|
|
panel.add(choice);
|
|
|
|
|
|
|
|
|
|
return panel;
|
|
|
|
|
}
|
|
|
|
|
@ -187,6 +208,7 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
if (currentQuestionDex > 0) {
|
|
|
|
|
currentQuestionDex--;
|
|
|
|
|
updateTitleLabel();
|
|
|
|
|
updateQuestion();
|
|
|
|
|
if (myAnswers[currentQuestionDex] == null) {
|
|
|
|
|
resetButtonColors();
|
|
|
|
|
}
|
|
|
|
|
@ -202,6 +224,7 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
if (currentQuestionDex < questionNum - 1) {
|
|
|
|
|
currentQuestionDex++;
|
|
|
|
|
updateTitleLabel();
|
|
|
|
|
updateQuestion();
|
|
|
|
|
if (myAnswers[currentQuestionDex] == null) {
|
|
|
|
|
resetButtonColors();
|
|
|
|
|
} else {
|
|
|
|
|
@ -216,6 +239,7 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
int confirm = JOptionPane.showConfirmDialog(SelTestFrame.this, "你确定要提交试卷吗?", "提示", JOptionPane.YES_NO_OPTION);
|
|
|
|
|
if (confirm == JOptionPane.YES_OPTION) {
|
|
|
|
|
int correctCount = 0;
|
|
|
|
|
correctCount = getScore(answers, myAnswers);
|
|
|
|
|
|
|
|
|
|
double accuracy = Math.round((double) correctCount / myAnswers.length * 10000) / 100.0;
|
|
|
|
|
double score = Math.round((double) correctCount * 100 / myAnswers.length * 10) / 10.0;
|
|
|
|
|
@ -224,7 +248,7 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
String[] options = {"返回主菜单", "继续做题"};
|
|
|
|
|
int choice = JOptionPane.showOptionDialog(
|
|
|
|
|
SelTestFrame.this,
|
|
|
|
|
"您答对了" + score + "道题,正确率为" + String.format("%.2f", accuracy) + "\n您的得分是: " + score + "分",
|
|
|
|
|
"您答对了" + correctCount + "道题,正确率为" + String.format("%.2f", accuracy) + "\n您的得分是: " + score + "分",
|
|
|
|
|
"测试结果",
|
|
|
|
|
JOptionPane.YES_NO_OPTION,
|
|
|
|
|
JOptionPane.INFORMATION_MESSAGE,
|
|
|
|
|
@ -237,8 +261,9 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
mainFrame.setVisible(true);
|
|
|
|
|
dispose();
|
|
|
|
|
} else if (choice == 1) {
|
|
|
|
|
mainFrame.reTryTest();
|
|
|
|
|
dispose();
|
|
|
|
|
mainFrame.setVisible(true);
|
|
|
|
|
mainFrame.reTryTest();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -292,7 +317,8 @@ public class SelTestFrame extends JFrame {
|
|
|
|
|
return score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getQuestion(String[] questions, int dex) {
|
|
|
|
|
return questions[dex];
|
|
|
|
|
private void updateQuestion() {
|
|
|
|
|
question.setText(multipleChoiceGenerator.GetQuestionList()[currentQuestionDex]);
|
|
|
|
|
choice.setText(multipleChoiceGenerator.GetChoiceList()[currentQuestionDex]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|