11/*
2- * Copyright (c) 2016, 2018 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2016, 2025 , 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+ import java .io .File ;
2425import java .awt .BorderLayout ;
2526import java .awt .Color ;
2627import java .awt .Point ;
2728import java .awt .Rectangle ;
2829import java .awt .Robot ;
2930import java .awt .event .InputEvent ;
3031import java .awt .image .BufferedImage ;
32+ import javax .imageio .ImageIO ;
3133import javax .swing .JDesktopPane ;
3234import javax .swing .JFrame ;
3335import javax .swing .JInternalFrame ;
@@ -51,6 +53,7 @@ public class JInternalFrameDraggingTest {
5153 private static JInternalFrame internalFrame ;
5254 private static int FRAME_SIZE = 500 ;
5355 private static Color BACKGROUND_COLOR = Color .ORANGE ;
56+ private static final int tolerance = 10 ;
5457
5558 public static void main (String [] args ) throws Exception {
5659 try {
@@ -69,14 +72,24 @@ public static void main(String[] args) throws Exception {
6972 BufferedImage img = robot .createScreenCapture (rect );
7073
7174 int testRGB = BACKGROUND_COLOR .getRGB ();
75+ Color testColor = new Color (testRGB );
7276 for (int i = 1 ; i < size ; i ++) {
7377 int rgbCW = img .getRGB (i , size / 2 );
7478 int rgbCH = img .getRGB (size / 2 , i );
75- if (rgbCW != testRGB || rgbCH != testRGB ) {
79+ Color rgbCWColor = new Color (rgbCW );
80+ Color rgbCHColor = new Color (rgbCH );
81+
82+ if (Math .abs (rgbCWColor .getRed () - testColor .getRed ()) > tolerance
83+ || Math .abs (rgbCWColor .getGreen () - testColor .getGreen ()) > tolerance
84+ || Math .abs (rgbCWColor .getBlue () - testColor .getBlue ()) > tolerance
85+ || Math .abs (rgbCHColor .getRed () - testColor .getRed ()) > tolerance
86+ || Math .abs (rgbCHColor .getGreen () - testColor .getGreen ()) > tolerance
87+ || Math .abs (rgbCHColor .getBlue () - testColor .getBlue ()) > tolerance ) {
7688 System .out .println ("i " + i + " rgbCW " +
7789 Integer .toHexString (rgbCW ) +
7890 " testRGB " + Integer .toHexString (testRGB ) +
7991 " rgbCH " + Integer .toHexString (rgbCH ));
92+ ImageIO .write (img , "png" , new File ("JInternalFrameDraggingTest.png" ));
8093 throw new RuntimeException ("Background color is wrong!" );
8194 }
8295 }
0 commit comments