implemented error handeling

This commit is contained in:
Jonas Hinterdorfer 2025-03-20 12:10:32 +01:00
parent 63ae5e2e1c
commit 649edaea78

View File

@ -71,12 +71,29 @@ public class FastWatchController {
this.linHandMinutes.setEndY(Math.sin(minuteRadians) * length * 0.8);
}
@FXML
public void btnAdjustOnAction(ActionEvent actionEvent) {
int[] time = Arrays.stream(this.txtTime.getText().split(":"))
.mapToInt(Integer::parseInt)
.toArray();
DayOfWeek dayOfWeek = this.cmbDayOfWeek.getValue();
WatchTime.getInstance().setTime(time[0], time[1], dayOfWeek);
try {
int[] time = Arrays.stream(this.txtTime.getText().split(":"))
.mapToInt(Integer::parseInt)
.toArray();
if (time.length != 2 || time[0] < 0 || time[0] > 23 || time[1] < 0 || time[1] > 59) {
throw new NumberFormatException("Invalid time format");
}
DayOfWeek dayOfWeek = this.cmbDayOfWeek.getValue();
WatchTime.getInstance().setTime(time[0], time[1], dayOfWeek);
} catch (NumberFormatException e) {
ShowAlert("Invalid time format", "Please use a this format HH:MM");
}
}
private void ShowAlert(String header,String content)
{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Invalid Input");
alert.setHeaderText(header);
alert.setContentText(content);
alert.showAndWait();
}
}