我的应用程序与第 3 方独立应用程序集成,它将在单独的线程中打开 JOptionPane 对话框,我正在运行线程以关闭所有打开的对话框。因此,在关闭之前,我需要在对话框中写入消息。
我试图实现的示例主程序:
public static void main(String[] args)throws Exception{
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
executor.scheduleAtFixedRate(() -> {
Window[] possibleWindow = Window.getWindows();
if (possibleWindow != null && possibleWindow.length > 0) {
System.out.println("Found " + possibleWindow.length + "Window(s) " + possibleWindow[0].getClass().getSuperclass());
for (int i = possibleWindow.length - 1; i >= 0; i--) {
try {
Window window = possibleWindow[i];
//here where I need to get the dialog box message before closing it.
window.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, 1, 1, TimeUnit.SECONDS);
JOptionPane.showMessageDialog(null, "test !!!!");
}