@@ -64,10 +64,13 @@ public class DnDRemoveFocusOwnerCrashTest {
6464 public static Frame frame ;
6565 public static Robot robot ;
6666 public static DragSourceButton dragSourceButton ;
67+ static volatile Point p ;
6768
6869 public static void main (String [] args ) throws Exception {
6970 try {
7071 robot = new Robot ();
72+ robot .setAutoWaitForIdle (true );
73+ robot .delay (FRAME_ACTIVATION_TIMEOUT );
7174 EventQueue .invokeAndWait (() -> {
7275 frame = new Frame ();
7376 dragSourceButton = new DragSourceButton ();
@@ -79,37 +82,33 @@ public static void main(String[] args) throws Exception {
7982 frame .add (dropTargetPanel );
8083 frame .pack ();
8184 frame .setVisible (true );
85+ });
8286
83- try {
84- robot .delay (FRAME_ACTIVATION_TIMEOUT );
85- } catch (Exception e ) {
86- e .printStackTrace ();
87- throw new RuntimeException ("The test failed." );
88- }
87+ robot .waitForIdle ();
88+ robot .delay (FRAME_ACTIVATION_TIMEOUT );
8989
90- Point p = dragSourceButton .getLocationOnScreen ();
90+ EventQueue .invokeAndWait (() -> {
91+ p = dragSourceButton .getLocationOnScreen ();
9192 p .translate (10 , 10 );
93+ });
9294
93- try {
94- Robot robot = new Robot ();
95- robot .mouseMove (p .x , p .y );
96- robot .keyPress (KeyEvent .VK_CONTROL );
97- robot .mousePress (InputEvent .BUTTON1_DOWN_MASK );
98- for (int dy = 0 ; dy < 50 ; dy ++) {
99- robot .mouseMove (p .x , p .y + dy );
100- robot .delay (10 );
101- }
102- robot .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
103- robot .keyRelease (KeyEvent .VK_CONTROL );
104- } catch (Exception e ) {
105- e .printStackTrace ();
106- throw new RuntimeException ("The test failed." );
95+ robot .delay (FRAME_ACTIVATION_TIMEOUT );
96+ robot .mouseMove (p .x , p .y );
97+ robot .delay (FRAME_ACTIVATION_TIMEOUT );
98+ robot .keyPress (KeyEvent .VK_CONTROL );
99+ robot .mousePress (InputEvent .BUTTON1_DOWN_MASK );
100+ for (int dy = 0 ; dy < 50 ; dy ++) {
101+ robot .mouseMove (p .x , p .y + dy );
102+ robot .delay (10 );
103+ }
104+ robot .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
105+ robot .keyRelease (KeyEvent .VK_CONTROL );
106+ } finally {
107+ EventQueue .invokeAndWait (() -> {
108+ if (frame != null ) {
109+ frame .dispose ();
107110 }
108111 });
109- } finally {
110- if (frame != null ) {
111- EventQueue .invokeAndWait (() -> frame .dispose ());
112- }
113112 }
114113 }
115114
0 commit comments