签到2:
签到界面上有时间显示,签到码输入框,开始签到,当倒计时结束,老师端和学生端都会显示签到结果,所以签到结果需要建表:(签到了的学生和未签到的学生,
这次签到的时间和签到码,班级号,)
签到有已签到,未签到
判断是否签的是以前的到就是看有没有结束时间
随机选人:
两遍遍历数据库,第一遍从数据库里把班级里所有学生挑出来,并定义一个变量每挑一个记录变量加1,然后使用redom随机数随机1-n这个范围内的数
第二遍再定义一个变量然后再遍历一遍直到数字等于随机数,然后把名字随机出来
if(receive.equals("Release success")){
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText(null);
alert.setContentText("发布签到成功");
// 显示提醒框并等待用户关闭
alert.showAndWait();
initializeTableView_second();
tabpane.getSelectionModel().select(Check_in);
Socket socket3 = new Socket("127.0.0.1", 10090);
String judgment3 = "update_check_in";
ObjectOutputStream oos3 = new ObjectOutputStream(socket3.getOutputStream());
oos3.writeObject(judgment3); //传送标志
oos3.writeObject(formattedTime);
ObjectInputStream ois3 = new ObjectInputStream(socket3.getInputStream());
Object obj = ois3.readObject();
if (studentsList != null && !studentsList.isEmpty()) {
studentsList.clear();
}
if (obj instanceof ArrayList<?>) {
studentsList = (ArrayList<String>) obj;
}
Map<String, String> studentStatusMap = new HashMap<>();
for (String student : studentsList) {
studentStatusMap.put(student, "未签到");
}
socket4 = new Socket("127.0.0.1", 10090);
judgment4 = "update_examine_check_in";
oos4 = new ObjectOutputStream(socket4.getOutputStream());
oos4.writeObject(judgment4);
Thread countdownThread = new Thread(() -> {
int totalSeconds = Integer.parseInt(minute) * 60 + Integer.parseInt(second_clock);
while (totalSeconds > 0) {
try {
// 将 totalSeconds 转换为分钟和秒钟
int minutes = totalSeconds / 60;
int seconds = totalSeconds % 60;
// 更新界面上的显示(这里使用 Platform.runLater 来在 JavaFX 应用程序线程中更新 UI)
Platform.runLater(() -> {
minutetext.setText(String.valueOf(minutes));
second_clocktext.setText(String.valueOf(seconds));
});
for (String student : studentsList) {
oos4.writeObject(student);
oos4.writeObject(formattedTime);
// 获取当前签到状态
ois4= new ObjectInputStream(socket4.getInputStream());
String status = (String) ois4.readObject();
if (!status.equals(studentStatusMap.get(student))) {
// 如果签到状态发生变化,更新 Map,并输出该学生的名字
studentStatusMap.put(student, status);
if (status.equals("已签到")) {
System.out.println(111);
success_name=student+" "+success_name;
// 在这里执行更新 TableView 的操作
Platform.runLater(() -> {
updateTableView(check_in_table, "已签到", success_name, formattedTime);
initializeTableView_second();
initializeTableView_second();
System.out.println(23);
});
}
}
}
// 每隔一秒钟减少一秒
Thread.sleep(1000);
totalSeconds--;
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
if(totalSeconds <= 0){
try {
LocalDateTime currentTime2 = LocalDateTime.now();
// 格式化当前系统时间,显示年、月、日、时、分和秒
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedTime2 = currentTime2.format(formatter2);
oos4.writeObject("111");
minutetext.setText("0");
second_clocktext.setText("0");
Socket socket4 = new Socket("127.0.0.1", 10090);
String judgment4 = "teacher_end_check_in";
ObjectOutputStream oos4 = new ObjectOutputStream(socket4.getOutputStream());
oos4.writeObject(judgment4); //传送标志
oos4.writeObject(formattedTime);
oos4.writeObject(formattedTime2);
ObjectInputStream ois4 = new ObjectInputStream(socket4.getInputStream());
String fail_name = (String) ois4.readObject();
Platform.runLater(() -> {
updateTableView(check_in_table, "未签到", fail_name, formattedTime2);
initializeTableView_second();
initializeTableView_second();
System.out.println(23);
});
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// 倒计时结束后执行的逻辑
// 这里你可以添加倒计时结束后需要执行的代码
});
// 启动倒计时线程
countdownThread.start();
}
签到功能:
随机抽人: