implemented error handeling
This commit is contained in:
parent
63ae5e2e1c
commit
649edaea78
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user