Binary file not shown.
@ -0,0 +1,21 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import frontend.LoginFrame;
|
||||
|
||||
public class MainApplication {
|
||||
public static void main(String[] args) {
|
||||
// 设置系统外观
|
||||
try {
|
||||
// 设置系统外观
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 创建并显示GUI
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
LoginFrame loginFrame = new LoginFrame();
|
||||
loginFrame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
import backend.MathCalculator;
|
||||
import backend.PrimarySchoolGenerator;
|
||||
|
||||
public class TestCalculator {
|
||||
public static void main(String[] args) {
|
||||
// 创建初中题目生成器
|
||||
PrimarySchoolGenerator generator = new PrimarySchoolGenerator();
|
||||
|
||||
// 生成随机初中题目
|
||||
String expression = generator.generateQuestion();
|
||||
|
||||
System.out.println("随机生成的小学题目: " + expression);
|
||||
|
||||
// 使用计算器计算
|
||||
String result = MathCalculator.calculateSimple(expression);
|
||||
System.out.println("计算器计算结果: " + result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
import java.util.Properties;
|
||||
import javax.mail.*;
|
||||
import javax.activation.DataSource;
|
||||
|
||||
/**
|
||||
* 测试JavaMail和Activation Framework是否能正常加载
|
||||
*/
|
||||
public class TestMailLibs {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("开始测试JavaMail和Activation Framework库...");
|
||||
|
||||
try {
|
||||
// 测试加载javax.mail.Session类
|
||||
Class<?> sessionClass = Class.forName("javax.mail.Session");
|
||||
System.out.println("✓ 成功加载javax.mail.Session类");
|
||||
System.out.println(" 类路径: " + sessionClass.getProtectionDomain().getCodeSource().getLocation());
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("✗ 无法加载javax.mail.Session类");
|
||||
System.err.println(" 错误信息: " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
// 测试加载javax.activation.DataSource类
|
||||
Class<?> dataSourceClass = Class.forName("javax.activation.DataSource");
|
||||
System.out.println("✓ 成功加载javax.activation.DataSource类");
|
||||
System.out.println(" 类路径: " + dataSourceClass.getProtectionDomain().getCodeSource().getLocation());
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.err.println("✗ 无法加载javax.activation.DataSource类");
|
||||
System.err.println(" 错误信息: " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
// 测试直接引用这些类
|
||||
Session session = Session.getDefaultInstance(new Properties());
|
||||
System.out.println("✓ 成功创建Session实例");
|
||||
} catch (Exception e) {
|
||||
System.err.println("✗ 无法创建Session实例");
|
||||
System.err.println(" 错误信息: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("\n当前classpath: " + System.getProperty("java.class.path"));
|
||||
System.out.println("\n测试完成");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
import backend.MathCalculator;
|
||||
|
||||
public class TestSquareCalculator {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("=== 测试平方符号计算功能 ===");
|
||||
|
||||
// 测试基本平方运算
|
||||
testExpression("47²");
|
||||
|
||||
// 测试包含平方的复杂表达式
|
||||
testExpression("(47²-53+95)");
|
||||
|
||||
// 测试其他可能的情况
|
||||
testExpression("2²+3²");
|
||||
testExpression("(2+3)²");
|
||||
testExpression("10-5²");
|
||||
}
|
||||
|
||||
private static void testExpression(String expression) {
|
||||
System.out.println("\n原始表达式: " + expression);
|
||||
String result = MathCalculator.calculateSimple(expression);
|
||||
System.out.println("计算结果: " + result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
import backend.MathCalculator;
|
||||
import backend.HighSchoolGenerator;
|
||||
|
||||
public class TestTrigonometricCalculator {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("=== 测试三角函数解析功能 ===");
|
||||
|
||||
// 测试简单三角函数
|
||||
testExpression("sin(30)");
|
||||
testExpression("cos(45)");
|
||||
testExpression("tan(60)");
|
||||
|
||||
// 测试包含表达式的三角函数
|
||||
testExpression("sin(30+15)");
|
||||
testExpression("cos(2*45)");
|
||||
testExpression("tan(60/2)");
|
||||
|
||||
// 测试复杂嵌套表达式的三角函数
|
||||
testExpression("sin((30+15)*2)");
|
||||
testExpression("cos(2*(45-10))");
|
||||
|
||||
// 使用高中生成器生成随机题目并测试
|
||||
System.out.println("\n=== 测试随机生成的高中题目 ===");
|
||||
HighSchoolGenerator generator = new HighSchoolGenerator();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String randomQuestion = generator.generateQuestion();
|
||||
testExpression(randomQuestion);
|
||||
}
|
||||
}
|
||||
|
||||
private static void testExpression(String expression) {
|
||||
System.out.println("\n原始表达式: " + expression);
|
||||
String result = MathCalculator.calculateSimple(expression);
|
||||
System.out.println("计算结果: " + result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
import backend.UserManager;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* 测试用户名检查功能的简单程序
|
||||
*/
|
||||
public class TestUsernameCheck {
|
||||
public static void main(String[] args) {
|
||||
// 初始化用户管理器
|
||||
UserManager userManager = UserManager.getInstance();
|
||||
|
||||
// 测试用例1: 检查一个不存在的用户名
|
||||
String testUsername1 = "testuser123";
|
||||
boolean exists1 = userManager.isUsernameRegistered(testUsername1);
|
||||
System.out.println("用户名 '" + testUsername1 + "' 是否已被注册: " + exists1);
|
||||
|
||||
// 测试用例2: 检查一个可能存在的用户名(根据实际情况调整)
|
||||
String testUsername2 = "admin"; // 常见的预设用户名
|
||||
boolean exists2 = userManager.isUsernameRegistered(testUsername2);
|
||||
System.out.println("用户名 '" + testUsername2 + "' 是否已被注册: " + exists2);
|
||||
|
||||
// 显示测试结果对话框
|
||||
StringBuilder resultMsg = new StringBuilder();
|
||||
resultMsg.append("用户名检查测试结果:\n\n");
|
||||
resultMsg.append("测试用户名1 ('").append(testUsername1).append("'): ");
|
||||
resultMsg.append(exists1 ? "已被注册" : "未被注册").append("\n");
|
||||
resultMsg.append("测试用户名2 ('").append(testUsername2).append("'): ");
|
||||
resultMsg.append(exists2 ? "已被注册" : "未被注册").append("\n\n");
|
||||
resultMsg.append("注册界面已更新,现在在发送验证码前会检查用户名是否被占用。");
|
||||
|
||||
JOptionPane.showMessageDialog(null, resultMsg.toString(), "测试结果", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,104 @@
|
||||
package backend;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class FileManager {
|
||||
|
||||
private String baseDir;
|
||||
|
||||
public FileManager() {
|
||||
this.baseDir = System.getProperty("user.dir") + File.separator + "papers";
|
||||
createBaseDirectory();
|
||||
}
|
||||
|
||||
// 创建基础目录
|
||||
private void createBaseDirectory() {
|
||||
File dir = new File(baseDir);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
// 为用户创建目录
|
||||
private String createUserDirectory(String username) {
|
||||
String userDir = baseDir + File.separator + username;
|
||||
File dir = new File(userDir);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
return userDir;
|
||||
}
|
||||
|
||||
// 生成文件名
|
||||
private String generateFileName() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||
return sdf.format(new Date()) + ".txt";
|
||||
}
|
||||
|
||||
// 保存题目到文件
|
||||
public void saveQuestions(String username, String[] questions) throws IOException {
|
||||
String userDir = createUserDirectory(username);
|
||||
String fileName = generateFileName();
|
||||
String filePath = userDir + File.separator + fileName;
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(filePath))) {
|
||||
for (int i = 0; i < questions.length; i++) {
|
||||
writer.println((i + 1) + ". " + questions[i]);
|
||||
if (i < questions.length - 1) {
|
||||
writer.println(); // 题目之间空一行
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("题目已保存到: " + filePath);
|
||||
}
|
||||
|
||||
// 检查题目是否重复(读取用户目录下所有文件)
|
||||
public Set<String> loadExistingQuestions(String username) {
|
||||
Set<String> existingQuestions = new HashSet<>();
|
||||
String userDir = baseDir + File.separator + username;
|
||||
File dir = new File(userDir);
|
||||
|
||||
if (dir.exists() && dir.isDirectory()) {
|
||||
File[] files = dir.listFiles((d, name) -> name.endsWith(".txt"));
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
StringBuilder questionBuilder = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.trim().isEmpty()) {
|
||||
if (questionBuilder.length() > 0) {
|
||||
// 移除题号
|
||||
String question = questionBuilder.toString().replaceAll("^\\d+\\.\\s*", "");
|
||||
existingQuestions.add(question.trim());
|
||||
questionBuilder.setLength(0);
|
||||
}
|
||||
} else {
|
||||
questionBuilder.append(line).append(" ");
|
||||
}
|
||||
}
|
||||
// 处理最后一个题目
|
||||
if (questionBuilder.length() > 0) {
|
||||
String question = questionBuilder.toString().replaceAll("^\\d+\\.\\s*", "");
|
||||
existingQuestions.add(question.trim());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("读取文件失败: " + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return existingQuestions;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,88 @@
|
||||
package backend;
|
||||
|
||||
public class HighSchoolGenerator extends QuestionGenerator {
|
||||
|
||||
private static final String[] BASIC_OPERATORS = {"+", "-", "*", "/"};
|
||||
private static final String[] TRIG_FUNCTIONS = {"sin", "cos", "tan"};
|
||||
|
||||
public HighSchoolGenerator() {
|
||||
super("高中");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateQuestion() {
|
||||
String question;
|
||||
do {
|
||||
question = generateSingleQuestion();
|
||||
} while (isDuplicate(question) || !question.matches(".*(sin|cos|tan)\\(.*\\).*")); // 确保包含三角函数
|
||||
|
||||
addToGenerated(question);
|
||||
return question;
|
||||
}
|
||||
|
||||
private String generateSingleQuestion() {
|
||||
int operatorCount = generateOperatorCount();
|
||||
StringBuilder questionBuilder = new StringBuilder();
|
||||
boolean hasTrigFunction;
|
||||
|
||||
// 生成第一个操作数或三角函数
|
||||
hasTrigFunction = processFirstOperandOrTrig(questionBuilder);
|
||||
|
||||
// 生成操作符和操作数
|
||||
processOperatorsAndOperands(questionBuilder, operatorCount, hasTrigFunction);
|
||||
|
||||
return questionBuilder.toString();
|
||||
}
|
||||
|
||||
private boolean processFirstOperandOrTrig(StringBuilder builder) {
|
||||
if (random.nextBoolean()) {
|
||||
// 使用三角函数
|
||||
String trigFunction = TRIG_FUNCTIONS[random.nextInt(TRIG_FUNCTIONS.length)];
|
||||
int angle = random.nextInt(360) + 1; // 1-360度
|
||||
builder.append(trigFunction).append("(").append(angle).append("°)");
|
||||
return true;
|
||||
} else {
|
||||
// 使用普通数字
|
||||
builder.append(generateOperand());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void processOperatorsAndOperands(StringBuilder builder, int operatorCount,
|
||||
boolean hasTrigFunction) {
|
||||
for (int i = 0; i < operatorCount; i++) {
|
||||
String operator = BASIC_OPERATORS[random.nextInt(BASIC_OPERATORS.length)];
|
||||
|
||||
// 决定下一个操作数是普通数字还是三角函数
|
||||
if (!hasTrigFunction && i == operatorCount - 1) {
|
||||
// 确保至少有一个三角函数
|
||||
appendTrigFunction(builder, operator);
|
||||
hasTrigFunction = true;
|
||||
} else if (random.nextBoolean()) {
|
||||
// 使用三角函数
|
||||
appendTrigFunction(builder, operator);
|
||||
hasTrigFunction = true;
|
||||
} else {
|
||||
// 使用普通数字
|
||||
appendBasicOperand(builder, operator, operatorCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void appendTrigFunction(StringBuilder builder, String operator) {
|
||||
String trigFunction = TRIG_FUNCTIONS[random.nextInt(TRIG_FUNCTIONS.length)];
|
||||
int angle = random.nextInt(360) + 1;
|
||||
builder.append(" ").append(operator).append(" ").append(trigFunction).append("(").append(angle)
|
||||
.append("°)");
|
||||
}
|
||||
|
||||
private void appendBasicOperand(StringBuilder builder, String operator, int operatorCount) {
|
||||
int operand = generateOperand();
|
||||
// 随机决定是否加括号
|
||||
if (random.nextBoolean() && operatorCount > 1) {
|
||||
builder.insert(0, "(").append(" ").append(operator).append(" ").append(operand).append(")");
|
||||
} else {
|
||||
builder.append(" ").append(operator).append(" ").append(operand);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,99 @@
|
||||
package backend;
|
||||
|
||||
public class MiddleSchoolGenerator extends QuestionGenerator {
|
||||
|
||||
private static final String[] BASIC_OPERATORS = {"+", "-", "*", "/"};
|
||||
private static final String[] ADVANCED_OPERATORS = {"²", "√"};
|
||||
|
||||
public MiddleSchoolGenerator() {
|
||||
super("初中");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateQuestion() {
|
||||
String question;
|
||||
do {
|
||||
question = generateSingleQuestion();
|
||||
} while (isDuplicate(question) || !question.matches(".*[²√].*")); // 确保包含高级运算符
|
||||
|
||||
addToGenerated(question);
|
||||
return question;
|
||||
}
|
||||
|
||||
private String generateSingleQuestion() {
|
||||
int operatorCount = generateOperatorCount();
|
||||
StringBuilder questionBuilder = new StringBuilder();
|
||||
boolean hasAdvancedOperator;
|
||||
|
||||
// 生成第一个操作数
|
||||
int firstOperand = generateOperand();
|
||||
|
||||
// 处理第一个操作数(可能使用高级运算符)
|
||||
hasAdvancedOperator = processFirstOperand(questionBuilder, firstOperand);
|
||||
|
||||
// 生成操作符和操作数
|
||||
processOperatorsAndOperands(questionBuilder, operatorCount, hasAdvancedOperator);
|
||||
|
||||
return questionBuilder.toString();
|
||||
}
|
||||
|
||||
private boolean processFirstOperand(StringBuilder builder, int operand) {
|
||||
// 随机决定第一个操作数是否使用高级运算符
|
||||
if (random.nextBoolean()) {
|
||||
String advancedOp = ADVANCED_OPERATORS[random.nextInt(ADVANCED_OPERATORS.length)];
|
||||
if (advancedOp.equals("²")) {
|
||||
builder.append(operand).append("²");
|
||||
} else {
|
||||
builder.append("√").append(operand);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
builder.append(operand);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void processOperatorsAndOperands(StringBuilder builder, int operatorCount,
|
||||
boolean hasAdvancedOperator) {
|
||||
for (int i = 0; i < operatorCount; i++) {
|
||||
String operator = determineOperator(i, operatorCount, hasAdvancedOperator);
|
||||
int operand = generateOperand();
|
||||
|
||||
if (operator.equals("²") || operator.equals("√")) {
|
||||
processAdvancedOperator(builder, operator, operand);
|
||||
hasAdvancedOperator = true;
|
||||
} else {
|
||||
processBasicOperator(builder, operator, operand, operatorCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String determineOperator(int currentIndex, int totalOperators,
|
||||
boolean hasAdvancedOperator) {
|
||||
if (!hasAdvancedOperator && currentIndex == totalOperators - 1) {
|
||||
// 确保至少有一个高级运算符
|
||||
return ADVANCED_OPERATORS[random.nextInt(ADVANCED_OPERATORS.length)];
|
||||
} else {
|
||||
return BASIC_OPERATORS[random.nextInt(BASIC_OPERATORS.length)];
|
||||
}
|
||||
}
|
||||
|
||||
private void processAdvancedOperator(StringBuilder builder, String operator, int operand) {
|
||||
String basicOp = BASIC_OPERATORS[random.nextInt(BASIC_OPERATORS.length)];
|
||||
if (operator.equals("²")) {
|
||||
builder.append(" ").append(basicOp).append(" ").append(operand).append("²");
|
||||
} else {
|
||||
builder.append(" ").append(basicOp).append(" √").append(operand);
|
||||
}
|
||||
}
|
||||
|
||||
private void processBasicOperator(StringBuilder builder, String operator, int operand,
|
||||
int operatorCount) {
|
||||
// 随机决定是否加括号
|
||||
if (random.nextBoolean() && operatorCount > 1) {
|
||||
builder.insert(0, "(").append(" ").append(operator).append(" ").append(operand).append(")");
|
||||
} else {
|
||||
builder.append(" ").append(operator).append(" ").append(operand);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,41 @@
|
||||
package backend;
|
||||
|
||||
public class PrimarySchoolGenerator extends QuestionGenerator {
|
||||
|
||||
private static final String[] OPERATORS = {"+", "-", "*", "/"};
|
||||
|
||||
public PrimarySchoolGenerator() {
|
||||
super("小学");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateQuestion() {
|
||||
String question;
|
||||
do {
|
||||
int operatorCount = generateOperatorCount1();
|
||||
StringBuilder questionBuilder = new StringBuilder();
|
||||
|
||||
// 生成第一个操作数
|
||||
questionBuilder.append(generateOperand());
|
||||
|
||||
// 生成操作符和操作数
|
||||
for (int i = 0; i < operatorCount; i++) {
|
||||
String operator = OPERATORS[random.nextInt(OPERATORS.length)];
|
||||
int operand = generateOperand();
|
||||
|
||||
// 随机决定是否加括号
|
||||
if (random.nextBoolean() && operatorCount > 1) {
|
||||
questionBuilder.insert(0, "(").append(" " + operator + " " + operand + ")");
|
||||
} else {
|
||||
questionBuilder.append(" " + operator + " " + operand);
|
||||
}
|
||||
}
|
||||
|
||||
question = questionBuilder.toString();
|
||||
|
||||
} while (isDuplicate(question));
|
||||
|
||||
addToGenerated(question);
|
||||
return question;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,42 @@
|
||||
package backend;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class User implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String email;
|
||||
private String username;
|
||||
private String password;
|
||||
private String userType; // 小学、初中、高中
|
||||
|
||||
public User(String email, String username, String password, String userType) {
|
||||
this.email = email;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
public void setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,137 @@
|
||||
package frontend;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import backend.UserManager;
|
||||
import backend.User;
|
||||
|
||||
public class ChangePasswordFrame extends JFrame {
|
||||
private JPasswordField oldPasswordField;
|
||||
private JPasswordField newPasswordField;
|
||||
private JPasswordField confirmPasswordField;
|
||||
private JButton changeButton, cancelButton;
|
||||
private UserManager userManager;
|
||||
private User currentUser;
|
||||
private MainFrame mainFrame;
|
||||
|
||||
public ChangePasswordFrame(MainFrame mainFrame, User user) {
|
||||
this.mainFrame = mainFrame;
|
||||
this.currentUser = user;
|
||||
this.userManager = UserManager.getInstance();
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setTitle("修改密码");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setSize(400, 300);
|
||||
setLocationRelativeTo(mainFrame);
|
||||
setResizable(false);
|
||||
|
||||
// 创建主面板
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 标题
|
||||
JLabel titleLabel = new JLabel("修改密码", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
titleLabel.setForeground(new Color(0, 120, 215));
|
||||
|
||||
// 表单面板
|
||||
JPanel formPanel = new JPanel(new GridLayout(4, 2, 10, 15));
|
||||
|
||||
JLabel oldPasswordLabel = new JLabel("原密码:");
|
||||
oldPasswordLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
oldPasswordField = new JPasswordField();
|
||||
|
||||
JLabel newPasswordLabel = new JLabel("新密码:");
|
||||
newPasswordLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
newPasswordField = new JPasswordField();
|
||||
|
||||
JLabel confirmPasswordLabel = new JLabel("确认新密码:");
|
||||
confirmPasswordLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
confirmPasswordField = new JPasswordField();
|
||||
|
||||
formPanel.add(oldPasswordLabel);
|
||||
formPanel.add(oldPasswordField);
|
||||
formPanel.add(newPasswordLabel);
|
||||
formPanel.add(newPasswordField);
|
||||
formPanel.add(confirmPasswordLabel);
|
||||
formPanel.add(confirmPasswordField);
|
||||
|
||||
// 按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
changeButton = new JButton("确认修改");
|
||||
cancelButton = new JButton("取消");
|
||||
|
||||
setupButtonStyle(changeButton);
|
||||
setupButtonStyle(cancelButton);
|
||||
|
||||
buttonPanel.add(changeButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
|
||||
// 添加组件到主面板
|
||||
mainPanel.add(titleLabel, BorderLayout.NORTH);
|
||||
mainPanel.add(formPanel, BorderLayout.CENTER);
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel);
|
||||
|
||||
// 添加事件监听器
|
||||
setupEventListeners();
|
||||
}
|
||||
|
||||
private void setupButtonStyle(JButton button) {
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
button.setBackground(new Color(0, 120, 215));
|
||||
button.setForeground(Color.BLACK);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
|
||||
}
|
||||
|
||||
private void setupEventListeners() {
|
||||
changeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleChangePassword();
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
// 回车键确认修改
|
||||
confirmPasswordField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleChangePassword();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleChangePassword() {
|
||||
String oldPassword = new String(oldPasswordField.getPassword());
|
||||
String newPassword = new String(newPasswordField.getPassword());
|
||||
String confirmPassword = new String(confirmPasswordField.getPassword());
|
||||
|
||||
if (oldPassword.isEmpty() || newPassword.isEmpty() || confirmPassword.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "请填写所有字段", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
String result = userManager.changePassword(currentUser.getEmail(), oldPassword, newPassword, confirmPassword);
|
||||
|
||||
if (result.equals("密码修改成功")) {
|
||||
JOptionPane.showMessageDialog(this, result, "修改成功", JOptionPane.INFORMATION_MESSAGE);
|
||||
dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, result, "修改失败", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,132 @@
|
||||
package frontend;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import backend.UserManager;
|
||||
import backend.User;
|
||||
|
||||
public class LoginFrame extends JFrame {
|
||||
private JTextField emailField;
|
||||
private JPasswordField passwordField;
|
||||
private JButton loginButton, registerButton;
|
||||
private UserManager userManager;
|
||||
|
||||
public LoginFrame() {
|
||||
userManager = UserManager.getInstance();
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setTitle("中小学数学学习软件 - 登录");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(400, 300);
|
||||
setLocationRelativeTo(null);
|
||||
setResizable(false);
|
||||
|
||||
// 创建主面板
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 标题
|
||||
JLabel titleLabel = new JLabel("中小学数学学习软件", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
|
||||
titleLabel.setForeground(new Color(0, 120, 215));
|
||||
|
||||
// 表单面板
|
||||
JPanel formPanel = new JPanel(new GridLayout(3, 2, 10, 10));
|
||||
|
||||
JLabel emailLabel = new JLabel("邮箱/用户名:");
|
||||
emailLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
emailField = new JTextField();
|
||||
|
||||
JLabel passwordLabel = new JLabel("密码:");
|
||||
passwordLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
passwordField = new JPasswordField();
|
||||
|
||||
formPanel.add(emailLabel);
|
||||
formPanel.add(emailField);
|
||||
formPanel.add(passwordLabel);
|
||||
formPanel.add(passwordField);
|
||||
|
||||
// 按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
loginButton = new JButton("登录");
|
||||
registerButton = new JButton("注册");
|
||||
|
||||
// 设置按钮样式
|
||||
setupButtonStyle(loginButton);
|
||||
setupButtonStyle(registerButton);
|
||||
|
||||
buttonPanel.add(loginButton);
|
||||
buttonPanel.add(registerButton);
|
||||
|
||||
// 添加组件到主面板
|
||||
mainPanel.add(titleLabel, BorderLayout.NORTH);
|
||||
mainPanel.add(formPanel, BorderLayout.CENTER);
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel);
|
||||
|
||||
// 添加事件监听器
|
||||
setupEventListeners();
|
||||
}
|
||||
|
||||
private void setupButtonStyle(JButton button) {
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
button.setBackground(new Color(0, 120, 215));
|
||||
button.setForeground(Color.BLACK);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
|
||||
}
|
||||
|
||||
private void setupEventListeners() {
|
||||
loginButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleLogin();
|
||||
}
|
||||
});
|
||||
|
||||
registerButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleRegister();
|
||||
}
|
||||
});
|
||||
|
||||
// 回车键登录
|
||||
passwordField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleLogin();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleLogin() {
|
||||
String identifier = emailField.getText().trim();
|
||||
String password = new String(passwordField.getPassword());
|
||||
|
||||
if (identifier.isEmpty() || password.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "请输入邮箱/用户名和密码", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
User user = userManager.authenticate(identifier, password);
|
||||
if (user != null) {
|
||||
// 登录成功,打开主界面
|
||||
dispose(); // 关闭登录窗口
|
||||
new MainFrame(user).setVisible(true);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "邮箱/用户名或密码错误", "登录失败", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRegister() {
|
||||
new RegistrationFrame(this).setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,157 @@
|
||||
package frontend;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import backend.User;
|
||||
import backend.UserManager;
|
||||
|
||||
public class MainFrame extends JFrame {
|
||||
private User currentUser;
|
||||
private JButton primarySchoolButton, middleSchoolButton, highSchoolButton;
|
||||
private JButton changePasswordButton, logoutButton;
|
||||
private UserManager userManager;
|
||||
|
||||
public MainFrame(User user) {
|
||||
this.currentUser = user;
|
||||
this.userManager = UserManager.getInstance();
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setTitle("中小学数学学习软件 - 主界面");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(500, 400);
|
||||
setLocationRelativeTo(null);
|
||||
setResizable(false);
|
||||
|
||||
// 创建主面板
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 欢迎面板
|
||||
JPanel welcomePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JLabel welcomeLabel = new JLabel("欢迎使用中小学数学学习软件", JLabel.CENTER);
|
||||
welcomeLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
welcomeLabel.setForeground(new Color(0, 120, 215));
|
||||
welcomePanel.add(welcomeLabel);
|
||||
|
||||
// 用户信息面板
|
||||
JPanel userInfoPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JLabel userInfoLabel = new JLabel("当前用户: " + currentUser.getUsername(), JLabel.CENTER);
|
||||
userInfoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
userInfoPanel.add(userInfoLabel);
|
||||
|
||||
// 学校选择面板
|
||||
JPanel schoolPanel = new JPanel(new GridLayout(3, 1, 15, 15));
|
||||
schoolPanel.setBorder(BorderFactory.createTitledBorder("请选择学校类型"));
|
||||
|
||||
primarySchoolButton = new JButton("小学");
|
||||
middleSchoolButton = new JButton("初中");
|
||||
highSchoolButton = new JButton("高中");
|
||||
|
||||
setupSchoolButtonStyle(primarySchoolButton);
|
||||
setupSchoolButtonStyle(middleSchoolButton);
|
||||
setupSchoolButtonStyle(highSchoolButton);
|
||||
|
||||
schoolPanel.add(primarySchoolButton);
|
||||
schoolPanel.add(middleSchoolButton);
|
||||
schoolPanel.add(highSchoolButton);
|
||||
|
||||
// 功能按钮面板
|
||||
JPanel functionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
changePasswordButton = new JButton("修改密码");
|
||||
logoutButton = new JButton("退出登录");
|
||||
|
||||
setupFunctionButtonStyle(changePasswordButton);
|
||||
setupFunctionButtonStyle(logoutButton);
|
||||
|
||||
functionPanel.add(changePasswordButton);
|
||||
functionPanel.add(logoutButton);
|
||||
|
||||
// 添加组件到主面板
|
||||
mainPanel.add(welcomePanel, BorderLayout.NORTH);
|
||||
mainPanel.add(userInfoPanel, BorderLayout.CENTER);
|
||||
mainPanel.add(schoolPanel, BorderLayout.CENTER);
|
||||
mainPanel.add(functionPanel, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel);
|
||||
|
||||
// 添加事件监听器
|
||||
setupEventListeners();
|
||||
}
|
||||
|
||||
private void setupSchoolButtonStyle(JButton button) {
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
button.setBackground(new Color(70, 130, 180));
|
||||
button.setForeground(Color.BLACK);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorder(BorderFactory.createEmptyBorder(15, 30, 15, 30));
|
||||
}
|
||||
|
||||
private void setupFunctionButtonStyle(JButton button) {
|
||||
button.setFont(new Font("微软雅黑", Font.PLAIN, 12));
|
||||
button.setBackground(new Color(169, 169, 169));
|
||||
button.setForeground(Color.BLACK);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
|
||||
}
|
||||
|
||||
private void setupEventListeners() {
|
||||
primarySchoolButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleSchoolSelection("小学");
|
||||
}
|
||||
});
|
||||
|
||||
middleSchoolButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleSchoolSelection("初中");
|
||||
}
|
||||
});
|
||||
|
||||
highSchoolButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleSchoolSelection("高中");
|
||||
}
|
||||
});
|
||||
|
||||
changePasswordButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new ChangePasswordFrame(MainFrame.this, currentUser).setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
logoutButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleLogout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleSchoolSelection(String schoolType) {
|
||||
// 设置用户类型
|
||||
userManager.setUserType(currentUser.getEmail(), schoolType);
|
||||
currentUser.setUserType(schoolType);
|
||||
|
||||
// 打开题目数量输入界面
|
||||
new QuestionCountFrame(this, currentUser).setVisible(true);
|
||||
}
|
||||
|
||||
private void handleLogout() {
|
||||
int result = JOptionPane.showConfirmDialog(this,
|
||||
"确定要退出登录吗?", "确认退出",
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
dispose();
|
||||
new LoginFrame().setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,134 @@
|
||||
package frontend;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import backend.User;
|
||||
|
||||
public class QuestionCountFrame extends JFrame {
|
||||
private JTextField countField;
|
||||
private JButton startButton, backButton;
|
||||
private User currentUser;
|
||||
private MainFrame mainFrame;
|
||||
|
||||
public QuestionCountFrame(MainFrame mainFrame, User user) {
|
||||
this.mainFrame = mainFrame;
|
||||
this.currentUser = user;
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setTitle("题目数量设置 - " + currentUser.getUserType());
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setSize(400, 250);
|
||||
setLocationRelativeTo(mainFrame);
|
||||
setResizable(false);
|
||||
|
||||
// 创建主面板
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 标题
|
||||
JLabel titleLabel = new JLabel("请输入题目数量", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
titleLabel.setForeground(new Color(0, 120, 215));
|
||||
|
||||
// 信息标签
|
||||
JLabel infoLabel = new JLabel("当前选择: " + currentUser.getUserType(), JLabel.CENTER);
|
||||
infoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
|
||||
// 输入面板
|
||||
JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JLabel countLabel = new JLabel("题目数量:");
|
||||
countLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
countField = new JTextField(10);
|
||||
countField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
|
||||
inputPanel.add(countLabel);
|
||||
inputPanel.add(countField);
|
||||
|
||||
// 按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
startButton = new JButton("开始答题");
|
||||
backButton = new JButton("返回");
|
||||
|
||||
setupButtonStyle(startButton);
|
||||
setupButtonStyle(backButton);
|
||||
|
||||
buttonPanel.add(startButton);
|
||||
buttonPanel.add(backButton);
|
||||
|
||||
// 添加组件到主面板
|
||||
mainPanel.add(titleLabel, BorderLayout.NORTH);
|
||||
mainPanel.add(infoLabel, BorderLayout.CENTER);
|
||||
mainPanel.add(inputPanel, BorderLayout.CENTER);
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel);
|
||||
|
||||
// 添加事件监听器
|
||||
setupEventListeners();
|
||||
}
|
||||
|
||||
private void setupButtonStyle(JButton button) {
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
button.setBackground(new Color(0, 120, 215));
|
||||
button.setForeground(Color.BLACK);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
|
||||
}
|
||||
|
||||
private void setupEventListeners() {
|
||||
startButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleStartQuiz();
|
||||
}
|
||||
});
|
||||
|
||||
backButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
// 回车键开始答题
|
||||
countField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleStartQuiz();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleStartQuiz() {
|
||||
String countText = countField.getText().trim();
|
||||
|
||||
if (countText.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "请输入题目数量", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int count = Integer.parseInt(countText);
|
||||
if (count <= 0) {
|
||||
JOptionPane.showMessageDialog(this, "题目数量必须大于0", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (count > 50) {
|
||||
JOptionPane.showMessageDialog(this, "题目数量不能超过50", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建答题界面
|
||||
dispose();
|
||||
new QuizFrame(mainFrame, currentUser, count).setVisible(true);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
JOptionPane.showMessageDialog(this, "请输入有效的数字", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,155 @@
|
||||
package frontend;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import backend.User;
|
||||
|
||||
public class ScoreFrame extends JFrame {
|
||||
private User currentUser;
|
||||
private MainFrame mainFrame;
|
||||
private double score;
|
||||
private int totalQuestions;
|
||||
private int correctCount;
|
||||
|
||||
public ScoreFrame(MainFrame mainFrame, User user, double score, int totalQuestions, int correctCount) {
|
||||
this.mainFrame = mainFrame;
|
||||
this.currentUser = user;
|
||||
this.score = score;
|
||||
this.totalQuestions = totalQuestions;
|
||||
this.correctCount = correctCount;
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
private void initializeUI() {
|
||||
setTitle("答题结果");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setSize(500, 400);
|
||||
setLocationRelativeTo(mainFrame);
|
||||
setResizable(false);
|
||||
|
||||
// 创建主面板
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 标题
|
||||
JLabel titleLabel = new JLabel("答题完成", JLabel.CENTER);
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 20));
|
||||
titleLabel.setForeground(new Color(0, 120, 215));
|
||||
|
||||
// 分数显示面板
|
||||
JPanel scorePanel = new JPanel(new GridLayout(4, 1, 10, 10));
|
||||
scorePanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 分数显示
|
||||
JLabel scoreLabel = new JLabel(String.format("得分: %.1f分", score), JLabel.CENTER);
|
||||
scoreLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
|
||||
scoreLabel.setForeground(getScoreColor(score));
|
||||
|
||||
// 详细信息
|
||||
JLabel detailLabel = new JLabel(
|
||||
String.format("答对 %d 题,共 %d 题", correctCount, totalQuestions),
|
||||
JLabel.CENTER
|
||||
);
|
||||
detailLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
||||
|
||||
// 百分比
|
||||
JLabel percentageLabel = new JLabel(
|
||||
String.format("正确率: %.1f%%", score),
|
||||
JLabel.CENTER
|
||||
);
|
||||
percentageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
||||
|
||||
// 评价
|
||||
JLabel commentLabel = new JLabel(getScoreComment(score), JLabel.CENTER);
|
||||
commentLabel.setFont(new Font("微软雅黑", Font.ITALIC, 14));
|
||||
commentLabel.setForeground(Color.GRAY);
|
||||
|
||||
scorePanel.add(scoreLabel);
|
||||
scorePanel.add(detailLabel);
|
||||
scorePanel.add(percentageLabel);
|
||||
scorePanel.add(commentLabel);
|
||||
|
||||
// 按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
JButton continueButton = new JButton("继续做题");
|
||||
JButton exitButton = new JButton("退出");
|
||||
|
||||
setupButtonStyle(continueButton);
|
||||
setupButtonStyle(exitButton);
|
||||
|
||||
buttonPanel.add(continueButton);
|
||||
buttonPanel.add(exitButton);
|
||||
|
||||
// 添加组件到主面板
|
||||
mainPanel.add(titleLabel, BorderLayout.NORTH);
|
||||
mainPanel.add(scorePanel, BorderLayout.CENTER);
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel);
|
||||
|
||||
// 添加事件监听器
|
||||
setupEventListeners(continueButton, exitButton);
|
||||
}
|
||||
|
||||
private void setupButtonStyle(JButton button) {
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
button.setBackground(new Color(0, 120, 215));
|
||||
button.setForeground(Color.BLACK);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
|
||||
}
|
||||
|
||||
private void setupEventListeners(JButton continueButton, JButton exitButton) {
|
||||
continueButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 返回主界面,用户可以重新选择学校类型
|
||||
dispose();
|
||||
mainFrame.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
exitButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
ScoreFrame.this,
|
||||
"确定要退出程序吗?",
|
||||
"确认退出",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Color getScoreColor(double score) {
|
||||
if (score >= 90) {
|
||||
return new Color(0, 150, 0); // 绿色 - 优秀
|
||||
} else if (score >= 70) {
|
||||
return new Color(255, 165, 0); // 橙色 - 良好
|
||||
} else if (score >= 60) {
|
||||
return new Color(255, 215, 0); // 金色 - 及格
|
||||
} else {
|
||||
return new Color(220, 20, 60); // 红色 - 不及格
|
||||
}
|
||||
}
|
||||
|
||||
private String getScoreComment(double score) {
|
||||
if (score >= 90) {
|
||||
return "太棒了!继续保持!";
|
||||
} else if (score >= 70) {
|
||||
return "做得不错,继续努力!";
|
||||
} else if (score >= 60) {
|
||||
return "及格了,再加把劲!";
|
||||
} else {
|
||||
return "需要多加练习哦!";
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in new issue