You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.0 KiB
136 lines
4.0 KiB
package com.wsf.mathapp.view;
|
|
|
|
import com.wsf.mathapp.controller.SceneManager;
|
|
import java.util.Objects;
|
|
import javafx.geometry.Insets;
|
|
import javafx.geometry.Pos;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.image.ImageView;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.scene.layout.Priority;
|
|
import javafx.scene.layout.Region;
|
|
import javafx.scene.layout.VBox;
|
|
import javafx.scene.text.Font;
|
|
|
|
public class ResultView {
|
|
private Scene scene;
|
|
private final SceneManager sceneManager;
|
|
private double score;
|
|
private String currentUsername;
|
|
|
|
public ResultView(SceneManager sceneManager) {
|
|
this.sceneManager = sceneManager;
|
|
this.currentUsername = sceneManager.getCurrentUserName();
|
|
createScene();
|
|
}
|
|
|
|
private void createScene() {
|
|
// 创建主容器
|
|
VBox mainContainer = new VBox();
|
|
mainContainer.setPadding(new Insets(20));
|
|
|
|
// 创建顶部用户信息栏
|
|
HBox userInfoBar = createUserInfoBar();
|
|
|
|
// 创建结果内容区域
|
|
VBox resultContent = createResultContent();
|
|
|
|
mainContainer.getChildren().addAll(userInfoBar, resultContent);
|
|
|
|
scene = new Scene(mainContainer, 500, 550); // 增加宽度和高度以适应新布局
|
|
}
|
|
|
|
private HBox createUserInfoBar() {
|
|
HBox userInfoBar = new HBox(10);
|
|
userInfoBar.setAlignment(Pos.CENTER_LEFT);
|
|
userInfoBar.setPadding(new Insets(0, 0, 20, 0));
|
|
return userInfoBar;
|
|
}
|
|
|
|
private VBox createResultContent() {
|
|
VBox resultContent = new VBox(30);
|
|
resultContent.setPadding(new Insets(20));
|
|
resultContent.setAlignment(Pos.CENTER);
|
|
|
|
Label titleLabel = new Label("答题完成");
|
|
titleLabel.setFont(Font.font(24));
|
|
|
|
Label scoreLabel = new Label();
|
|
scoreLabel.setFont(Font.font(48));
|
|
|
|
Label messageLabel = new Label();
|
|
messageLabel.setFont(Font.font(18));
|
|
|
|
Button restartButton = new Button("再次练习");
|
|
restartButton.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white; -fx-font-size: 16px;");
|
|
restartButton.setPrefSize(200, 50);
|
|
|
|
Button mainMenuButton = new Button("返回主菜单");
|
|
mainMenuButton.setStyle("-fx-background-color: #2196F3; -fx-text-fill: white; -fx-font-size: 16px;");
|
|
mainMenuButton.setPrefSize(200, 50);
|
|
|
|
Button exitButton = new Button("退出系统");
|
|
exitButton.setStyle("-fx-background-color: #757575; -fx-text-fill: white; -fx-font-size: 16px;");
|
|
exitButton.setPrefSize(200, 50);
|
|
|
|
restartButton.setOnAction(e -> {
|
|
sceneManager.showLevelSelectionView();
|
|
});
|
|
|
|
mainMenuButton.setOnAction(e -> {
|
|
sceneManager.showMainMenuView();
|
|
});
|
|
|
|
exitButton.setOnAction(e -> {
|
|
System.exit(0);
|
|
});
|
|
|
|
resultContent.getChildren().addAll(
|
|
titleLabel, scoreLabel, messageLabel,
|
|
restartButton, mainMenuButton, exitButton
|
|
);
|
|
|
|
return resultContent;
|
|
}
|
|
|
|
public void setScore(double score) {
|
|
this.score = score;
|
|
updateScoreDisplay();
|
|
}
|
|
|
|
|
|
private void updateScoreDisplay() {
|
|
if (scene != null) {
|
|
VBox mainContainer = (VBox) scene.getRoot();
|
|
VBox resultContent = (VBox) mainContainer.getChildren().get(1);
|
|
Label scoreLabel = (Label) resultContent.getChildren().get(1);
|
|
Label messageLabel = (Label) resultContent.getChildren().get(2);
|
|
|
|
int percentage = (int) (score * 100);
|
|
scoreLabel.setText(percentage + "分");
|
|
|
|
// 根据分数设置不同的颜色和评语
|
|
if (score >= 0.9) {
|
|
scoreLabel.setStyle("-fx-text-fill: #4CAF50;");
|
|
messageLabel.setText("优秀!表现非常出色!");
|
|
} else if (score >= 0.7) {
|
|
scoreLabel.setStyle("-fx-text-fill: #FF9800;");
|
|
messageLabel.setText("良好!继续加油!");
|
|
} else if (score >= 0.6) {
|
|
scoreLabel.setStyle("-fx-text-fill: #FFC107;");
|
|
messageLabel.setText("及格!还有进步空间!");
|
|
} else {
|
|
scoreLabel.setStyle("-fx-text-fill: #f44336;");
|
|
messageLabel.setText("需要多加练习!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public Scene getScene() {
|
|
return scene;
|
|
}
|
|
|
|
} |