1
1
/*
2
- * Copyright (c) 2007, 2010 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2007, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
49
49
" move the pointer between B to C.",
50
50
*/
51
51
52
- import java .awt .*;
53
- import java .awt .event .*;
52
+ import java .awt .BorderLayout ;
53
+ import java .awt .Button ;
54
+ import java .awt .Component ;
55
+ import java .awt .EventQueue ;
56
+ import java .awt .Frame ;
57
+ import java .awt .Point ;
58
+ import java .awt .Robot ;
59
+ import java .awt .Window ;
60
+ import java .awt .event .MouseAdapter ;
61
+ import java .awt .event .MouseEvent ;
62
+ import java .lang .reflect .InvocationTargetException ;
63
+
54
64
import test .java .awt .regtesthelpers .Util ;
55
- import javax .swing .*;
65
+
66
+ import javax .swing .JButton ;
67
+ import javax .swing .JFrame ;
56
68
57
69
public class SpuriousExitEnter_3 {
58
- static JFrame frame = new JFrame ("SpuriousExitEnter_3_LW" );
59
- static JButton jbutton = new JButton ("jbutton" );
60
- static Frame frame1 = new Frame ("SpuriousExitEnter_3_HW" );
61
- static Button button1 = new Button ("button" );
62
-
63
- static EnterExitAdapter frameAdapter ;
64
- static EnterExitAdapter buttonAdapter ;
65
- static Robot r = Util .createRobot ();
66
-
67
- public static void testCase (Window w , Component comp ) {
68
- frameAdapter = new EnterExitAdapter (w );
69
- buttonAdapter = new EnterExitAdapter (comp );
70
-
71
- w .addMouseListener (frameAdapter );
72
- comp .addMouseListener (buttonAdapter );
73
-
74
- w .setSize (200 , 200 );
75
- w .add (comp , BorderLayout .NORTH );
76
- w .setLocationRelativeTo (null );
77
- w .setVisible (true );
78
-
79
- Point centerA = new Point (comp .getLocationOnScreen ().x + comp .getWidth () / 2 ,
80
- comp .getLocationOnScreen ().y + comp .getHeight () / 2 );
81
- Point centerB = new Point (w .getLocationOnScreen ().x + w .getWidth () / 2 ,
82
- w .getLocationOnScreen ().y + w .getHeight () / 2 );
83
- //for moving from A outside: don't cross the A area. Move straight to the right.
84
- Point centerC_1 = new Point (w .getLocationOnScreen ().x + w .getWidth () + 20 , //go right off the border
85
- comp .getLocationOnScreen ().y + comp .getHeight () / 2 ); //don't cross the A area!
86
-
87
- //for moving from B outside: don't cross the B area. Move straight to the bottom.
88
- Point centerC_2 = new Point (w .getLocationOnScreen ().x + w .getWidth () / 2 ,
89
- w .getLocationOnScreen ().y + w .getHeight () + 20 ); //go below the bottom border
70
+ static JFrame frame ;
71
+ static JButton jbutton ;
72
+
73
+ static Frame frame1 ;
74
+ static Button button1 ;
75
+
76
+ static final Robot r = Util .createRobot ();
77
+
78
+ static volatile EnterExitAdapter frameAdapter ;
79
+ static volatile EnterExitAdapter buttonAdapter ;
80
+ static volatile Point centerA ;
81
+ static volatile Point centerB ;
82
+ static volatile Point centerC_1 ;
83
+ static volatile Point centerC_2 ;
84
+
85
+ public static void testCase (Window w , Component comp ) throws InterruptedException , InvocationTargetException {
86
+ EventQueue .invokeAndWait (()-> {
87
+ frameAdapter = new EnterExitAdapter (w );
88
+ buttonAdapter = new EnterExitAdapter (comp );
89
+
90
+ w .addMouseListener (frameAdapter );
91
+ comp .addMouseListener (buttonAdapter );
92
+
93
+ w .setSize (200 , 200 );
94
+ w .add (comp , BorderLayout .NORTH );
95
+ w .setLocationRelativeTo (null );
96
+ w .setVisible (true );
97
+ });
98
+
99
+ r .waitForIdle ();
100
+ r .delay (1000 );
101
+
102
+ EventQueue .invokeAndWait (()-> {
103
+ centerA = new Point (comp .getLocationOnScreen ().x + comp .getWidth () / 2 ,
104
+ comp .getLocationOnScreen ().y + comp .getHeight () / 2 );
105
+ centerB = new Point (w .getLocationOnScreen ().x + w .getWidth () / 2 ,
106
+ w .getLocationOnScreen ().y + w .getHeight () / 2 );
107
+ //for moving from A outside: don't cross the A area. Move straight to the right.
108
+ centerC_1 = new Point (w .getLocationOnScreen ().x + w .getWidth () + 20 , //go right off the border
109
+ comp .getLocationOnScreen ().y + comp .getHeight () / 2 ); //don't cross the A area!
110
+
111
+ //for moving from B outside: don't cross the B area. Move straight to the bottom.
112
+ centerC_2 = new Point (w .getLocationOnScreen ().x + w .getWidth () / 2 ,
113
+ w .getLocationOnScreen ().y + w .getHeight () + 20 ); //go below the bottom border
114
+ });
115
+
90
116
//A and B areas
91
117
Util .pointOnComp (comp , r );
92
118
Util .waitForIdle (r );
@@ -118,12 +144,23 @@ public static void testCase(Window w, Component comp) {
118
144
Util .waitForIdle (r );
119
145
}
120
146
121
- public static void main (String []s )
122
- {
123
- //LW case:
124
- testCase (frame , jbutton );
125
- //HW case
126
- testCase (frame1 , button1 );
147
+
148
+ public static void main (String []s ) throws InterruptedException , InvocationTargetException {
149
+ EventQueue .invokeAndWait (() -> {
150
+ frame = new JFrame ("SpuriousExitEnter_3_LW" );
151
+ jbutton = new JButton ("jbutton" );
152
+
153
+ frame1 = new Frame ("SpuriousExitEnter_3_HW" );
154
+ button1 = new Button ("button" );
155
+ });
156
+
157
+ try {
158
+ testCase (frame , jbutton ); //LW case
159
+ testCase (frame1 , button1 ); //HW case
160
+ } finally {
161
+ EventQueue .invokeLater (frame ::dispose );
162
+ EventQueue .invokeLater (frame1 ::dispose );
163
+ }
127
164
}
128
165
129
166
private static void moveBetween (Robot r , Point first , Point second ) {
@@ -150,9 +187,9 @@ private static void checkEvents(EnterExitAdapter adapter, int entered, int exite
150
187
151
188
152
189
class EnterExitAdapter extends MouseAdapter {
153
- private Component target ;
154
- private int enteredEventCount = 0 ;
155
- private int exitedEventCount = 0 ;
190
+ private final Component target ;
191
+ private volatile int enteredEventCount = 0 ;
192
+ private volatile int exitedEventCount = 0 ;
156
193
157
194
public EnterExitAdapter (Component target ) {
158
195
this .target = target ;
@@ -170,7 +207,7 @@ public int getExitedEventCount(){
170
207
}
171
208
172
209
public void zeroCounters (){
173
- System .out .println ("Zeroeing on " +target .getClass ().getName ());
210
+ System .out .println ("Zeroing on " +target .getClass ().getName ());
174
211
enteredEventCount = 0 ;
175
212
exitedEventCount = 0 ;
176
213
}
0 commit comments