我有TIMER_funk-倒数到0的方法

我有弹出新窗口的方法

public void DialogWindowkk(String Title, String Header, String Content)  {
    Alert alert = new Alert(AlertType.WARNING);
    alert.setTitle(Title);
    alert.setHeaderText(Header);
    alert.setContentText(Content);
    Dialog dialog = new Dialog();
    Stage stage = new Stage();
    stage = (Stage) dialog.getDialogPane().getScene().getWindow();
    alert.showAndWait();};


我需要当firs计时器开始工作时,然后弹出第一个窗口(task3)。当第二个计时器开始工作时,将弹出一个新窗口(任务4)。但现在仅适用于计时器。 Windows不会弹出。方法有效。

Runnable task1 = () -> {TIMER_funk(task11);};
Runnable task2 = () -> {TIMER_funk(task22);};
Runnable task3 = () -> {DialogWindowkk("WOW you cool");};
Runnable task4 = () -> {DialogWindowkk("HAHAHAp");};

ExecutorService service = Executors.newSingleThreadExecutor();
 for(int i=1; i<11; i++){

    service.submit(task3);

    service.submit(() -> {
    Thread.sleep(1000);
    рр.cancel();
    return null;});

    service.submit(task1);

    service.submit(() -> {
    Thread.sleep(sleep1);
    рр.cancel();
    return null;});

    service.submit(task4);

    service.submit(() -> {
    Thread.sleep(1000);
    рр.cancel();
    return null;});

    service.submit(task2);

    service.submit(() -> {
    Thread.sleep(sleep2);
    рр.cancel();return null;});  }

最佳答案

将对话框任务提交到事件队列。例如:

EventQueue.invokeLater(task3);Platform.runLater(task3);而不是service.submit(task3);

关于java - 可运行不执行应执行的操作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44181456/

10-10 20:26