【发布时间】:2020-07-10 07:53:51
【问题描述】:
当我点击一个按钮时,我想做两件事:第一,打开一个对话框,第二,执行一个方法(在一个 jar 文件中)。问题是,当我单击按钮时,首先执行该方法,然后打开对话框。代码是这样的:
button.addClickListener(event -> start());
public void start() {
dialog.open(); //Second, it opens the Dialog
methodInJar(); //First it executes this method
}
注意:无论是对话框、通知还是界面的任何变化,都会发生同样的事情。
有谁知道问题出在哪里?
谢谢。
PD。这是全班:
package com.example.test;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.page.Push;
import com.vaadin.flow.router.Route;
@Route("myView")
@Push
public class MyView extends VerticalLayout {
private UI ui;
private Dialog dialog = new Dialog();
public MyView(){
addAttachListener(event -> {
this.ui = event.getUI();
});
add(new Button("some button", click -> start()));
}
private void start(){
this.ui.access(() -> {
dialog.open();
});
methodInJarTest();
}
private void methodInJarTest() {
try {
System.out.println("JAR test - 10 seconds pause");
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
【问题讨论】: