11/*
2- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2020, 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
2222 */
2323
2424import java .awt .Color ;
25+ import java .awt .Dimension ;
2526import java .awt .Frame ;
2627import java .awt .Point ;
28+ import java .awt .Rectangle ;
2729import java .awt .Robot ;
30+ import java .awt .Toolkit ;
31+ import java .awt .image .BufferedImage ;
32+ import java .io .File ;
33+ import java .io .IOException ;
2834import java .util .List ;
2935
36+ import javax .imageio .ImageIO ;
37+
3038/**
3139 * @test
3240 * @key headful
@@ -58,6 +66,7 @@ private static void test() {
5866 Color .GREEN , Color .MAGENTA , Color .CYAN ,
5967 Color .BLUE )) {
6068 frame .dispose ();
69+ robot .waitForIdle ();
6170 frame .setBackground (color );
6271 frame .setVisible (true );
6372 checkPixels (color );
@@ -68,14 +77,25 @@ private static void checkPixels(final Color color) {
6877 int attempt = 0 ;
6978 while (true ) {
7079 Point p = frame .getLocationOnScreen ();
71- Color pixel = robot . getPixelColor ( p . x + frame .getWidth () / 2 ,
72- p . y + frame . getHeight () / 2 );
80+ p . translate ( frame . getWidth () / 2 , frame .getHeight () / 2 );
81+ Color pixel = robot . getPixelColor ( p . x , p . y );
7382 if (color .equals (pixel )) {
7483 return ;
7584 }
76- if (attempt > 10 ) {
85+ frame .repaint ();
86+ if (attempt > 11 ) {
7787 System .err .println ("Expected: " + color );
7888 System .err .println ("Actual: " + pixel );
89+ System .err .println ("Point: " + p );
90+ Dimension screenSize =
91+ Toolkit .getDefaultToolkit ().getScreenSize ();
92+ BufferedImage screen = robot .createScreenCapture (
93+ new Rectangle (screenSize ));
94+ try {
95+ File output = new File ("ScreenCapture.png" );
96+ System .err .println ("Dump screen to: " + output );
97+ ImageIO .write (screen , "png" , output );
98+ } catch (IOException ex ) {}
7999 throw new RuntimeException ("Too many attempts: " + attempt );
80100 }
81101 // skip Robot.waitForIdle to speedup the common case, but also take
0 commit comments