簽到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();}
簽到功能:
隨機抽人:
?