我正在构建JavaFX程序,并且使用了JFXDatePicker和JFXTimePicker,但是我希望设置后每秒钟刷新一次。
在我的FXML文件中:
<JFXDatePicker fx:id="dateSHS" promptText="dd/mm/yy"
GridPane.rowIndex="9" GridPane.columnIndex="1" GridPane.columnSpan="2"
GridPane.halignment="LEFT"/>
<Button fx:id="saveDate" onAction="#saveSimulationConditions" text="Save"
GridPane.rowIndex="9" GridPane.columnIndex="3"/>
<Label text="Time (Hour, Minutes)"
GridPane.rowIndex="10" GridPane.columnIndex="0" GridPane.halignment="LEFT"/>
<JFXTimePicker fx:id="timeSHS" promptText="hour:minute"
GridPane.rowIndex="10" GridPane.columnIndex="1" GridPane.halignment="LEFT"
/>
<Button fx:id="saveTime" onAction="#saveSimulationConditions" text="Save"
GridPane.rowIndex="10" GridPane.columnIndex="3"/>
控制器文件:
public void saveSimulationConditions(ActionEvent event) {
if (event.getSource().equals(saveDate)) {
consoleTextField.setText("[" + timeSHS.getValue().toString() + "] " + "The date has been changed to " + dateSHS.getValue().toString() + ".\n" + consoleTextField.getText());
leftPanelDate.setText("Date: " + dateSHS.getValue().toString());
} else if (event.getSource().equals(saveTime)) {
consoleTextField.setText("[" + timeSHS.getValue().toString() + "] " + "The time has been changed to " + timeSHS.getValue().toString() + ".\n" + consoleTextField.getText());
leftPanelTime.setText("Time: " + timeSHS.getValue().toString());
}
}
我当时正在考虑在FXML文件中设置一个线程,并且该线程中的时间将每次增加一秒。将秒数增加60次后,将秒数还原为零,并增加一分钟。我该怎么办?
答案 0 :(得分:-1)
您不需要使用事件来执行此操作,因为事件驱动的模型用于对特定动作做出反应。您的问题仅在于定义计划的任务,每秒更换一次窗格。