I'm creating an application in which I test a certain number of interface features, and when an error occurs I would like an error message to show.
Then the application should take a screenshot of the entire screen, and finally the error message closes without any help from the user.
To this end, I tried to use JDialog as below:
JOptionPane pane = new JOptionPane("Error message", JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = pane.createDialog("Error");
dialog.addWindowListener(null);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
Application.takeScreenshot();
dialog.setVisible(false);
I was wondering if there is a specific method to close it. I looked up the documentation and I can't seem to find it. I tried to find a relevant question on SO, but couldn't find one that addresses my problem.
I wonder if there is a way to get the window handle, and then close it using that, or simply send a "CLOSE" or "Press_ok" event to the window?
Edit: It seems to me as if the code entirely stops running when the messagebox shows, as if there was a Thread.sleep() until window is closed manually by the user.
If possible, a code sample would be helpful.
Thanks