gpt4 book ai didi

java - 在 swt 的特定时间段后自动关闭 shell

转载 作者:行者123 更新时间:2023-11-29 05:43:15 24 4
gpt4 key购买 nike

<分区>

我正在尝试在 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();
}
}
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com