修改了一下ListView的打印格式,老师和学生显示的格式不一样:
public static class CourseListCell extends ListCell<Course> {
private final String identity;
public CourseListCell(String identity) {
this.identity = identity;
}
@Override
protected void updateItem(Course course, boolean empty) {
super.updateItem(course, empty);
if (empty || course == null) {
setText(null);
return;
}
if (identity.equals("学生")) {
setText(course.getCourseName() + "\t\t\t\t\t\t\t\t" + course.getTeacherName());
} else if (identity.equals("老师")) {
setText(course.getGrade() + "\t\t" + course.getSpeciality() + "\t\t\t\t\t" + course.getCourseName() );
}
}
}
public static Callback<ListView<Course>, ListCell<Course>> studentCellFactory() {
return param -> new CourseListCell("学生");
}
public static Callback<ListView<Course>, ListCell<Course>> teacherCellFactory() {
return param -> new CourseListCell("老师");
}
老师端:
学生端:
二,完善了双击界面:
@FXML
void teacherCourseDetails(MouseEvent event) {
if(event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY)
{
Stage stage = new Stage();
stage.setTitle("学习一点通");
stage.setWidth(1200);
stage.setHeight(700);
FXMLLoader fxmlLoader = new FXMLLoader(MyStage.class.getResource("/com/project/resources/fxml/course.fxml"));
Parent parent = null;
try {
parent = fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
stage.setScene(new Scene(parent,450,756));
stage.show();
}
}
三,时间差的计算:
1.改善了一些签到的bug:
老师发布签到能获取的小时不能超过今天最晚的时候:
public static int getHours()
{
ZoneId currentZone = ZoneId.systemDefault();
LocalDateTime now = LocalDateTime.now(currentZone);
LocalDateTime tomorrow = now.plusDays(1).withHour(0).withMinute(0).withSecond(0);
Duration duration = Duration.between(now, tomorrow);
return (int) duration.toHours();
}
2.签到截止时也不超过今天的计算:
String HH = hours.getValue().toString();
String MM = hours.getValue().toString();
String SS = second.getValue().toString();
// 获取当前系统日期和时间
LocalDateTime now = LocalDateTime.now();
// 将 ComboBox 中的时间加上去,得到一个新的时间
LocalDateTime newTime = now.plusHours(Integer.parseInt(HH))
.plusMinutes(Integer.parseInt(MM))
.plusSeconds(Integer.parseInt(SS));
// 判断新的时间是否超过今天
if (newTime.toLocalDate().isEqual(now.toLocalDate())) {
// 时间未超过今天,将结果格式化为字符串并输出
String formattedResult = newTime.format(DateTimeFormatter.ISO_LOCAL_TIME);
} else {
// 时间已经超过了今天
AlertInsert.showError("时间不能超过今天!请您重新选择!");
}
}
目前主要是删除学生和注销课程时学生查看到课程消息没有什么思路,后面再看看。希望能把学生端的页面显示正式完成吧。