24/05/14总结

签到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();

            }

签到功能:

随机抽人:





 

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值