4242
4343public class Test6541987 implements Runnable {
4444 private static Robot robot ;
45+ private static JFrame frame ;
4546
46- public static void main (String [] args ) throws AWTException {
47- robot = new Robot ();
48- // test escape after selection
49- start ();
50- click (KeyEvent .VK_ESCAPE );
51- robot .waitForIdle ();
52- // test double escape after editing
53- start ();
54- click (KeyEvent .VK_1 );
55- click (KeyEvent .VK_0 );
56- click (KeyEvent .VK_ESCAPE );
57- click (KeyEvent .VK_ESCAPE );
58- robot .waitForIdle ();
59- // all windows should be closed
60- for (Window window : Window .getWindows ()) {
61- if (window .isVisible ()) {
62- throw new Error ("found visible window: " + window .getName ());
47+ public static void main (String [] args ) throws Exception {
48+ try {
49+ robot = new Robot ();
50+ robot .setAutoDelay (100 );
51+ // test escape after selection
52+ start ();
53+ click (KeyEvent .VK_ESCAPE );
54+ robot .waitForIdle ();
55+ // test double escape after editing
56+ start ();
57+ click (KeyEvent .VK_1 );
58+ click (KeyEvent .VK_0 );
59+ click (KeyEvent .VK_ESCAPE );
60+ click (KeyEvent .VK_ESCAPE );
61+ robot .waitForIdle ();
62+ robot .delay (500 );
63+ // all windows should be closed
64+ for (Window window : Window .getWindows ()) {
65+ if (window .isVisible ()) {
66+ throw new Error ("found visible window: " + window .getName ());
67+ }
68+ }
69+ } finally {
70+ if (frame != null ) {
71+ SwingUtilities .invokeAndWait (frame ::dispose );
6372 }
6473 }
6574 }
@@ -85,7 +94,8 @@ private static void click(int...keys) {
8594
8695 public void run () {
8796 String title = getClass ().getName ();
88- JFrame frame = new JFrame (title );
97+ frame = new JFrame (title );
98+ frame .setLocationRelativeTo (null );
8999 frame .setVisible (true );
90100
91101 Color color = JColorChooser .showDialog (frame , title , Color .BLACK );
0 commit comments