我想在javafx中創建一個cbt,如果時間流逝,我會遇到一個不知道如何自動提交表單的問題,並且可能是其中一個學生尚未完成測試。此外,我想知道如何禁用javafx中的表單如何在javafx中自動提交表單
0
A
回答
2
禁用Node
可以通過簡單地調用node.setDisable(true)
來完成。由於孩子也被自動禁用,只要沒有其他孩子不應該被禁用,您也可以爲要禁用的父母Node
這樣做。
超時可以很容易地使用實施ScheduledExecutorService
:
private ScheduledExecutorService executorService;
@Override
public void start(Stage primaryStage) {
TextField tf = new TextField();
Label label = new Label("Your Name: ");
Button submit = new Button("submit");
GridPane root = new GridPane();
label.setLabelFor(tf);
root.addRow(0, label, tf);
root.add(submit, 1, 1);
root.setPadding(new Insets(10));
root.setVgap(5);
root.setHgap(5);
AtomicBoolean done = new AtomicBoolean(false);
executorService = Executors.newScheduledThreadPool(1);
// schedule timeout for execution in 10 sec
ScheduledFuture future = executorService.schedule(() -> {
if (!done.getAndSet(true)) {
System.out.println("timeout");
Platform.runLater(() -> {
root.setDisable(true);
});
}
}, 10, TimeUnit.SECONDS);
submit.setOnAction((ActionEvent event) -> {
if (!done.getAndSet(true)) {
// print result and stop timeout task
future.cancel(false);
System.out.println("Your name is " + tf.getText());
}
});
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
@Override
public void stop() throws Exception {
executorService.shutdown();
}
如果你想顯示在用戶界面的時候,一個Timeline
可能比不過一個ScheduledExecutorService
更適合:
@Override
public void start(Stage primaryStage) {
TextField tf = new TextField();
Label label = new Label("Your Name:");
Button submit = new Button("submit");
GridPane root = new GridPane();
label.setLabelFor(tf);
Label time = new Label("Time:");
ProgressBar bar = new ProgressBar();
time.setLabelFor(bar);
root.addRow(0, time, bar);
root.addRow(1, label, tf);
root.add(submit, 1, 2);
root.setPadding(new Insets(10));
root.setVgap(5);
root.setHgap(5);
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(bar.progressProperty(), 0)),
new KeyFrame(Duration.seconds(10), evt -> {
// execute at the end of animation
System.out.println("timeout");
root.setDisable(true);
}, new KeyValue(bar.progressProperty(), 1))
);
timeline.play();
submit.setOnAction((ActionEvent event) -> {
// stop animation
timeline.pause();
System.out.println("Your name is " + tf.getText());
});
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
+0
如果你沒有顯示剩餘時間,'PauseTransition'會比'ScheduledExecutorService'簡單... –
相關問題
- 1. 如何在struts動作中提交表單以提交表單
- 2. 如何在Symfony中自提交表單?
- 3. 如何自動錶單提交?
- 4. AnguarJS自動提交表單
- 5. 自動提交表單
- 6. Ajax自動錶單提交
- 7. JavaScript - 自動提交表單
- 8. 自動提交表單(cURL)
- 9. Javascript自動錶單提交
- 10. 表單自動提交
- 11. 自動提交HTML表單
- 12. 如何在提交後提交表單中的自動填空字段
- 13. 如何在javascript中自動提交表單?
- 14. 如何在jsf中自動提交表單
- 15. 如何在AngularJS中生效時自動提交表單
- 16. 如何在另一個表單中提交表單值提交
- 17. 自動提交表單不能在鉻
- 18. 自動提交表單在20秒
- 19. 自動提交HTML表單自PHP
- 20. 如何在單一提交中提交多個表單
- 21. 如何提交表單當自動完成建議被選中
- 22. 如何在提交表單後自動刷新頁面
- 23. 如何在Facebook上提交表單時自動分享
- 24. ReCaptcha:如何在驗證碼發送時自動提交表單
- 25. 如何在刷信用卡後自動提交表單?
- 26. 如何在提交表單後自動添加值
- 27. 如何在提交表單時自動顯示號碼
- 28. 如何提交表單散列或自
- 29. 在任何瀏覽器中自動提交表單的腳本
- 30. 如何自動加載上次提交(單次提交)?
如果您向我們提供一些代碼,對我們來說更容易。 http://stackoverflow.com/help/how-to-ask –