39
39
import java .awt .Robot ;
40
40
import java .awt .Toolkit ;
41
41
import java .awt .image .BufferedImage ;
42
+ import javax .imageio .ImageIO ;
43
+ import java .io .File ;
42
44
43
45
/*
44
46
* @test
@@ -57,6 +59,7 @@ public class bug7154030 {
57
59
58
60
private static JButton button = null ;
59
61
private static JFrame frame ;
62
+ private static int locx , locy , frw , frh ;
60
63
61
64
public static void main (String [] args ) throws Exception {
62
65
try {
@@ -86,14 +89,21 @@ public void run() {
86
89
87
90
frame .setContentPane (desktop );
88
91
frame .setSize (300 , 300 );
89
- frame .setLocation ( 0 , 0 );
92
+ frame .setLocationRelativeTo ( null );
90
93
frame .setVisible (true );
91
94
frame .setDefaultCloseOperation (JFrame .DISPOSE_ON_CLOSE );
92
95
}
93
96
});
94
97
95
- robot .waitForIdle (500 );
96
- imageInit = robot .createScreenCapture (new Rectangle (0 , 0 , 300 , 300 ));
98
+ robot .waitForIdle (1000 );
99
+
100
+ Rectangle bounds = frame .getBounds ();
101
+ locx = bounds .x ;
102
+ locy = bounds .y ;
103
+ frw = bounds .width ;
104
+ frh = bounds .height ;
105
+
106
+ imageInit = robot .createScreenCapture (new Rectangle (locx , locy , frw , frh ));
97
107
98
108
SwingUtilities .invokeAndWait (new Runnable () {
99
109
@@ -104,8 +114,10 @@ public void run() {
104
114
});
105
115
106
116
robot .waitForIdle (500 );
107
- imageShow = robot .createScreenCapture (new Rectangle (0 , 0 , 300 , 300 ));
117
+ imageShow = robot .createScreenCapture (new Rectangle (locx , locy , frw , frh ));
108
118
if (Util .compareBufferedImages (imageInit , imageShow )) {
119
+ ImageIO .write (imageInit , "png" , new File ("imageInit.png" ));
120
+ ImageIO .write (imageShow , "png" , new File ("imageShow.png" ));
109
121
throw new Exception ("Failed to show opaque button" );
110
122
}
111
123
@@ -119,9 +131,11 @@ public void run() {
119
131
});
120
132
121
133
robot .waitForIdle (500 );
122
- imageHide = robot .createScreenCapture (new Rectangle (0 , 0 , 300 , 300 ));
134
+ imageHide = robot .createScreenCapture (new Rectangle (locx , locy , frw , frh ));
123
135
124
136
if (!Util .compareBufferedImages (imageInit , imageHide )) {
137
+ ImageIO .write (imageInit , "png" , new File ("imageInit.png" ));
138
+ ImageIO .write (imageHide , "png" , new File ("imageHide.png" ));
125
139
throw new Exception ("Failed to hide opaque button" );
126
140
}
127
141
@@ -136,7 +150,7 @@ public void run() {
136
150
});
137
151
138
152
robot .waitForIdle (500 );
139
- imageInit = robot .createScreenCapture (new Rectangle (0 , 0 , 300 , 300 ));
153
+ imageInit = robot .createScreenCapture (new Rectangle (locx , locy , frw , frh ));
140
154
141
155
SwingUtilities .invokeAndWait (new Runnable () {
142
156
@@ -147,7 +161,7 @@ public void run() {
147
161
});
148
162
149
163
robot .waitForIdle (500 );
150
- imageShow = robot .createScreenCapture (new Rectangle (0 , 0 , 300 , 300 ));
164
+ imageShow = robot .createScreenCapture (new Rectangle (locx , locy , frw , frh ));
151
165
152
166
SwingUtilities .invokeAndWait (new Runnable () {
153
167
@@ -158,13 +172,17 @@ public void run() {
158
172
});
159
173
160
174
if (Util .compareBufferedImages (imageInit , imageShow )) {
175
+ ImageIO .write (imageInit , "png" , new File ("imageInit.png" ));
176
+ ImageIO .write (imageShow , "png" , new File ("imageShow.png" ));
161
177
throw new Exception ("Failed to show non-opaque button" );
162
178
}
163
179
164
180
robot .waitForIdle (500 );
165
- imageHide = robot .createScreenCapture (new Rectangle (0 , 0 , 300 , 300 ));
181
+ imageHide = robot .createScreenCapture (new Rectangle (locx , locy , frw , frh ));
166
182
167
183
if (!Util .compareBufferedImages (imageInit , imageHide )) {
184
+ ImageIO .write (imageInit , "png" , new File ("imageInit.png" ));
185
+ ImageIO .write (imageHide , "png" , new File ("imageHide.png" ));
168
186
throw new Exception ("Failed to hide non-opaque button" );
169
187
}
170
188
} finally {
0 commit comments