我有以下代码:
import org.eclipse.swt.widgets.Display;
public class ProvaShow {
public static void main(String[] args) {
try {
ProvaShow window = new ProvaShow();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() throws InterruptedException {
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
Thread.sleep(3000);
shell.open();
shell.layout();
shell.forceActive();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
如果打开另一个应用程序(例如浏览器网站),我该如何强制显示我正在运行的窗口?
答案 0 :(得分:0)
如果要显示窗口3秒钟然后关闭它,请将Thread.sleep(3000);
替换为
display.timerExec(3000, new Runnable() {
@Override
public void run() {
shell.dispose();
}
});
并使shell
最终......