我正在尝试在 java swt 应用程序中创建一个 shell 作为对话框 Shell。有两个按钮“接受”和“拒绝”。我想如果用户在 30 秒内没有点击任何按钮,那么 shell 将被自动处理。为此,我正在尝试以下代码,但它不起作用。请帮助我使用任何想法或建议
public class ServiceRequestDialog extends Dialog {
public ServiceRequestDialog(Shell parent,String nameofrequestor) {
// Pass the default styles here
this(parent,SWT.NO_TRIM|SWT.ON_TOP|SWT.DIALOG_TRIM|SWT.APPLICATION_MODAL);
this.parent=parent;
nameofRequester=nameofrequestor;
}
public ServiceRequestDialog(Shell parent, int style) {
// Let users override the default styles
super(parent, style);
}
public Shell open() {
shell = new Shell(getParent(), getStyle());
shell.setText(getText());
shell.setLocation(parent.getLocation().x+190, parent.getLocation().y+215);
shell.setSize(279, 181);
shell.setLayout(new FormLayout());
......
shell.open();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
// Return the entered value, or null
try {
System.out.println("Thread Sleep");
Thread.sleep(15000);
dispose();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return shell;
}
public void dispose(){
try {
if (shell != null) {
if (shell.isDisposed()==false) {
shell.dispose();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}