I'm trying to display a timer which counts and displays seconds in a label after clicking the start button but I'm not getting desired output.Here's my code of the controller and FXML file...
public class FXMLDocumentController implements Initializable {
@FXML
private static final Integer STARTTIME = 0;
private Timeline timeline;
private Label timerLabel = new Label();
private IntegerProperty timeSeconds = new SimpleIntegerProperty(STARTTIME);
Button button = new Button();
public void handle(ActionEvent event) {
if (timeline != null) {
timeline.stop();
}
timeSeconds.set(STARTTIME);
timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(STARTTIME+1),
new KeyValue(timeSeconds, 0)));
timeline.playFromStart();
timerLabel.textProperty().bind(timeSeconds.asString());
}
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
and this is my FXML code..
<Button fx:id="button" layoutX="120.0" layoutY="40.0"
mnemonicParsing="false" text="Start Timmer" onAction="#handle" />
<Label layoutX="132.0" layoutY="92.0" prefHeight="17.0" prefWidth="65.0"
textFill="#f20b0b">
<font>
<Font size="24.0" />
</font>
</Label>