按钮与题型的对应关系 2025年3月21日14:33:32
parent
1aaf69fbdf
commit
b131f7da38
|
|
@ -1,5 +1,6 @@
|
|||
package com.zhangmeng.online.exam.ui.admin;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.components.ExamButtonComponent;
|
||||
import com.zhangmeng.online.exam.ui.components.ExamComponent;
|
||||
import com.zhangmeng.online.exam.ui.components.ShortAnswerComponent;
|
||||
import javafx.scene.Scene;
|
||||
|
|
@ -73,10 +74,10 @@ public class LoginPage extends AnchorPane {
|
|||
gridPane.setLayoutY(59.0);
|
||||
gridPane.setPrefHeight(159.0);
|
||||
gridPane.setPrefWidth(275.0);
|
||||
AnchorPane.setBottomAnchor(gridPane,97.0);
|
||||
AnchorPane.setLeftAnchor(gridPane,125.0);
|
||||
AnchorPane.setRightAnchor(gridPane,127.0);
|
||||
AnchorPane.setTopAnchor(gridPane,59.0);
|
||||
AnchorPane.setBottomAnchor(gridPane, 97.0);
|
||||
AnchorPane.setLeftAnchor(gridPane, 125.0);
|
||||
AnchorPane.setRightAnchor(gridPane, 127.0);
|
||||
AnchorPane.setTopAnchor(gridPane, 59.0);
|
||||
|
||||
Label label1 = new Label("账号");
|
||||
Label label2 = new Label("密码");
|
||||
|
|
@ -103,8 +104,9 @@ public class LoginPage extends AnchorPane {
|
|||
|
||||
Stage stage = new Stage();
|
||||
// IndexPage shortAnswerComponent = new IndexPage();
|
||||
ExamComponent shortAnswerComponent = new ExamComponent();
|
||||
scene = new Scene(shortAnswerComponent, 1280, 720);
|
||||
|
||||
PaperPage paperPage = new PaperPage();
|
||||
scene = new Scene(paperPage, 1280, 720);
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("在线考试系统");
|
||||
stage.show();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.zhangmeng.online.exam.ui.admin;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.components.ExamButtonComponent;
|
||||
import com.zhangmeng.online.exam.ui.components.ExamComponent;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/3/21 14:08
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class PaperPage extends AnchorPane {
|
||||
private SplitPane splitPane;
|
||||
public PaperPage() {
|
||||
ExamComponent examComponent = new ExamComponent();
|
||||
ExamButtonComponent examButtonComponent = new ExamButtonComponent(examComponent.getTotalCount(),examComponent);
|
||||
examButtonComponent.setMaxWidth(300);
|
||||
|
||||
splitPane = new SplitPane();
|
||||
splitPane.getItems().addAll(examButtonComponent,examComponent);
|
||||
this.getChildren().add(splitPane);
|
||||
splitPane.prefWidthProperty().bind(this.widthProperty());
|
||||
splitPane.prefHeightProperty().bind(this.heightProperty());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.zhangmeng.online.exam.ui.components;
|
||||
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 考试按钮组件
|
||||
* @author zm
|
||||
* @date 2025/3/21 13:59
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class ExamButtonComponent extends FlowPane {
|
||||
|
||||
private ExamComponent examComponent;
|
||||
|
||||
private SimpleIntegerProperty countButton = new SimpleIntegerProperty(0);
|
||||
|
||||
private final Map<Button, Integer> buttonMap = new HashMap<>();
|
||||
|
||||
public ExamButtonComponent(int count,ExamComponent examComponent) {
|
||||
this.examComponent = examComponent;
|
||||
this.countButton.set(count);
|
||||
this.setHgap(10);
|
||||
this.setVgap(10);
|
||||
this.setPadding(new Insets(10));
|
||||
for (int i = 1; i <= count; i++) {
|
||||
Button button = new Button(String.valueOf(i));
|
||||
button.setPrefWidth(45);
|
||||
button.setOnAction(event -> {
|
||||
|
||||
//滚动到指定题目
|
||||
int currentIndex = buttonMap.get(button);
|
||||
examComponent.scrollToIndex(currentIndex);
|
||||
|
||||
});
|
||||
buttonMap.put(button,i);
|
||||
this.getChildren().add(button);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -13,6 +13,8 @@ import javafx.collections.ObservableList;
|
|||
import javafx.css.StyleableProperty;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.AccessibleRole;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
|
|
@ -51,6 +53,8 @@ public class ExamComponent extends ScrollPane {
|
|||
// 简答题
|
||||
private final ObservableList<ShortAnswerComponent> shortAnswerComponents = FXCollections.observableArrayList();
|
||||
|
||||
private final SimpleIntegerProperty totalCount = new SimpleIntegerProperty(0);
|
||||
|
||||
private VBox vBox;
|
||||
|
||||
public ExamComponent() {
|
||||
|
|
@ -84,9 +88,15 @@ public class ExamComponent extends ScrollPane {
|
|||
}
|
||||
}
|
||||
|
||||
Label label = new Label("一. 选择题");
|
||||
label.setFont(new Font("黑体", 18));
|
||||
this.vBox.getChildren().add(label);
|
||||
int count = singleChoiceComponents.size() + multiChoiceComponents.size() + judgmentComponents.size() + numericalComponents.size() + fillInBlankComponents.size() + shortAnswerComponents.size();
|
||||
totalCount.set(count);
|
||||
|
||||
|
||||
// Label label = new Label("一. 选择题");
|
||||
// label.setFont(new Font("黑体", 18));
|
||||
// this.vBox.getChildren().add(label);
|
||||
|
||||
|
||||
this.vBox.getChildren().addAll(singleChoiceComponents);
|
||||
this.vBox.getChildren().addAll(multiChoiceComponents);
|
||||
this.vBox.getChildren().addAll(judgmentComponents);
|
||||
|
|
@ -100,6 +110,26 @@ public class ExamComponent extends ScrollPane {
|
|||
|
||||
}
|
||||
|
||||
public void scrollToIndex(int currentIndex) {
|
||||
Node node = this.vBox.getChildren().get(currentIndex-1);
|
||||
scroll_to_bottom(node);
|
||||
}
|
||||
|
||||
private void scroll_to_bottom(Node targetNode) {
|
||||
// 获取你要滚动到的特定标签,这里假设是第 25 个标签
|
||||
|
||||
// 获取 VBox 在 ScrollPane 中的偏移量
|
||||
double targetNodeLayoutY = targetNode.getLayoutY();
|
||||
// 获取 VBox 的实际高度
|
||||
double vboxHeight = this.vBox.getHeight();
|
||||
// 获取 ScrollPane 的视口高度
|
||||
double scrollPaneViewportHeight = this.getViewportBounds().getHeight();
|
||||
// 计算需要的垂直滚动值,确保目标节点在视口中居中
|
||||
double vvalue = targetNodeLayoutY / (vboxHeight - scrollPaneViewportHeight);
|
||||
// 设置 ScrollPane 的垂直滚动值
|
||||
this.setVvalue(vvalue);
|
||||
}
|
||||
|
||||
//简答题
|
||||
private void shortAnswer(JSONObject question) {
|
||||
String list = question.getString("options");
|
||||
|
|
@ -115,7 +145,7 @@ public class ExamComponent extends ScrollPane {
|
|||
option.put("content", map.get("content").toString());
|
||||
optionList.add(option);
|
||||
}
|
||||
ShortAnswerComponent shortAnswerComponent = new ShortAnswerComponent(SINGLE_CHOICE_COUNT.get() + "." + question.getString("name"), optionList);
|
||||
ShortAnswerComponent shortAnswerComponent = new ShortAnswerComponent(SHORT_ANSWER_COUNT.get() + "." + question.getString("name"), optionList);
|
||||
Map<String, Object> context = new HashMap<>();
|
||||
context.put("question_id", question.getString("id"));
|
||||
context.put("paper_id", 1);
|
||||
|
|
@ -149,7 +179,7 @@ public class ExamComponent extends ScrollPane {
|
|||
option.put("content", map.get("content").toString());
|
||||
optionList.add(option);
|
||||
}
|
||||
TrueFalseComponent trueFalseComponent = new TrueFalseComponent(SINGLE_CHOICE_COUNT.get() + "." + question.getString("name"), optionList);
|
||||
TrueFalseComponent trueFalseComponent = new TrueFalseComponent(JUDGMENT_COUNT.get() + "." + question.getString("name"), optionList);
|
||||
Map<String, Object> context = new HashMap<>();
|
||||
context.put("question_id", question.getString("id"));
|
||||
context.put("paper_id", 1);
|
||||
|
|
@ -189,4 +219,18 @@ public class ExamComponent extends ScrollPane {
|
|||
singleChoiceComponents.add(singleChoiceComponent);
|
||||
SINGLE_CHOICE_COUNT.set(SINGLE_CHOICE_COUNT.get() + 1);
|
||||
}
|
||||
|
||||
public int getTotalCount() {
|
||||
return totalCount.get();
|
||||
}
|
||||
|
||||
public VBox getvBox() {
|
||||
return vBox;
|
||||
}
|
||||
|
||||
public void setvBox(VBox vBox) {
|
||||
this.vBox = vBox;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue