11/*
2- * Copyright (c) 2010, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2010, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2121 * questions.
2222 */
2323
24- /*
25- @test
26- @key headful
27- @bug 6988428
28- @summary Tests whether shape is always set
29- @author anthony.petrov@oracle.com: area=awt.toplevel
30- @run main ShapeNotSetSometimes
31- */
3224
3325
3426import java .awt .Color ;
27+ import java .awt .Dimension ;
3528import java .awt .EventQueue ;
3629import java .awt .Frame ;
3730import java .awt .Graphics ;
3831import java .awt .Point ;
3932import java .awt .Rectangle ;
4033import java .awt .Robot ;
34+ import java .awt .Toolkit ;
4135import java .awt .geom .Area ;
4236import java .awt .geom .Ellipse2D ;
4337import java .awt .geom .Rectangle2D ;
38+ import java .io .File ;
39+ import java .io .IOException ;
40+ import javax .imageio .ImageIO ;
4441
42+ /*
43+ * @test
44+ * @key headful
45+ * @bug 6988428
46+ * @summary Tests whether shape is always set
47+ * @run main ShapeNotSetSometimes
48+ */
4549
4650public class ShapeNotSetSometimes {
4751
4852 private Frame backgroundFrame ;
4953 private Frame window ;
50- private static final Color BACKGROUND_COLOR = Color .GREEN ;
51- private static final Color SHAPE_COLOR = Color .WHITE ;
54+
5255 private Point [] pointsOutsideToCheck ;
5356 private Point [] shadedPointsToCheck ;
5457 private Point innerPoint ;
55-
5658 private final Rectangle bounds = new Rectangle (220 , 400 , 300 , 300 );
5759
5860 private static Robot robot ;
61+ private static final Color BACKGROUND_COLOR = Color .GREEN ;
62+ private static final Color SHAPE_COLOR = Color .WHITE ;
5963
6064 public ShapeNotSetSometimes () throws Exception {
6165 EventQueue .invokeAndWait (this ::initializeGUI );
6266 robot .waitForIdle ();
67+ robot .delay (1000 );
6368 }
6469
6570 private void initializeGUI () {
@@ -124,7 +129,7 @@ public void paint(Graphics g) {
124129 public static void main (String [] args ) throws Exception {
125130 robot = new Robot ();
126131
127- for (int i = 0 ; i < 50 ; i ++) {
132+ for (int i = 1 ; i <= 50 ; i ++) {
128133 System .out .println ("Attempt " + i );
129134 new ShapeNotSetSometimes ().doTest ();
130135 }
@@ -136,7 +141,6 @@ private void doTest() throws Exception {
136141
137142 EventQueue .invokeAndWait (window ::toFront );
138143 robot .waitForIdle ();
139-
140144 robot .delay (500 );
141145
142146 try {
@@ -173,8 +177,8 @@ private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpecte
173177 );
174178
175179 if (mustBeExpectedColor != expectedColor .equals (actualColor )) {
180+ captureScreen ();
176181 System .out .printf ("window.getX() = %3d, window.getY() = %3d\n " , window .getX (), window .getY ());
177-
178182 System .err .printf (
179183 "Checking for transparency failed: point: %3d, %3d\n \t actual %s\n \t expected %s%s\n " ,
180184 screenX ,
@@ -185,4 +189,18 @@ private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpecte
185189 throw new RuntimeException ("Test failed. The shape has not been applied." );
186190 }
187191 }
192+
193+ private static void captureScreen () {
194+ Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
195+ Rectangle screenBounds = new Rectangle (0 , 0 , screenSize .width , screenSize .height );
196+ try {
197+ ImageIO .write (
198+ robot .createScreenCapture (screenBounds ),
199+ "png" ,
200+ new File ("Screenshot.png" )
201+ );
202+ } catch (IOException e ) {
203+ e .printStackTrace ();
204+ }
205+ }
188206}
0 commit comments