I am designing a timer application. Right now, I would like the user to enter the number of minutes to set the timer. Here is my code so far:
VBox myLayout = new VBox();
Arc timerFace = new Arc();
TextField timeField = new TextField("Enter Timer Length (1-60min)");
myLayout.getChildren().add(timerFace);
myLayout.getChildren().add(timeField);
//Arc Specifications
timerFace.setLength(270);
timerFace.setStartAngle(90);
timerFace.setRadiusX(100);
timerFace.setRadiusY(100);
timerFace.setFill(Color.rgb(29, 69, 40));
timerFace.setStroke(Color.BLACK);
timerFace.setStrokeType(StrokeType.INSIDE);
timerFace.setType(ArcType.ROUND);
//Text Field Specifications
timeField.setOnAction(myEvent);
timeField.setOnAction((evt) -> timerFace.setLength(Double.parseDouble(timeField.getCharacters().toString())*6));
While it is functional, I would like to include an if statement in the event handling so that if the user entered number is not within range, it will default to a specified value (360) instead of inducing strange behavior. However, I do not know how to write this, as I only understand the implementation with the lambda function.
I tried to use the Ternary operator as a workaround but the specifications of the lambda function do not allow it. I also looked into the public Java Docs, but I’m struggling to comprehend how to implement the information there.