83 } 84 } 85 if (graphicsConfig == null) { 86 System.out.println("The system does not support translucency. Consider the test passed."); 87 return; 88 } 89 90 Robot r = new Robot(); 91 Color color1 = r.getPixelColor(100, 100); // (0, 0) in frame coordinates 92 93 SwingUtilities.invokeAndWait(new Runnable() { 94 public void run() { 95 initAndShowGUI(); 96 } 97 }); 98 r.waitForIdle(); 99 100 if (!paintComponentCalled) { 101 throw new RuntimeException("Test FAILED: panel's paintComponent() method is not called"); 102 } 103 104 Color newColor1 = r.getPixelColor(100, 100); 105 // unfortunately, robot.getPixelColor() doesn't work for some unknown reason 106 // Color newColor2 = r.getPixelColor(200, 200); 107 BufferedImage bim = r.createScreenCapture(new Rectangle(200, 200, 1, 1)); 108 Color newColor2 = new Color(bim.getRGB(0, 0)); 109 110 // Frame must be transparent at (100, 100) in screen coords 111 if (!color1.equals(newColor1)) { 112 System.err.println("color1 = " + color1); 113 System.err.println("newColor1 = " + newColor1); 114 throw new RuntimeException("Test FAILED: frame pixel at (0, 0) is not transparent"); 115 } 116 117 // Frame must be RED at (200, 200) in screen coords 118 if (!newColor2.equals(Color.RED)) { 119 System.err.println("newColor2 = " + newColor2); 120 throw new RuntimeException("Test FAILED: frame pixel at (100, 100) is not red (transparent?)"); 121 } 122 123 System.out.println("Test PASSED"); 124 } 125 } | 83 } 84 } 85 if (graphicsConfig == null) { 86 System.out.println("The system does not support translucency. Consider the test passed."); 87 return; 88 } 89 90 Robot r = new Robot(); 91 Color color1 = r.getPixelColor(100, 100); // (0, 0) in frame coordinates 92 93 SwingUtilities.invokeAndWait(new Runnable() { 94 public void run() { 95 initAndShowGUI(); 96 } 97 }); 98 r.waitForIdle(); 99 100 if (!paintComponentCalled) { 101 throw new RuntimeException("Test FAILED: panel's paintComponent() method is not called"); 102 } 103 Thread.sleep(1500); 104 105 Color newColor1 = r.getPixelColor(100, 100); 106 Color newColor2 = r.getPixelColor(200, 200); 107 108 // Frame must be transparent at (100, 100) in screen coords 109 if (!color1.equals(newColor1)) { 110 System.err.println("color1 = " + color1); 111 System.err.println("newColor1 = " + newColor1); 112 throw new RuntimeException("Test FAILED: frame pixel at (0, 0) is not transparent"); 113 } 114 115 // Frame must be RED at (200, 200) in screen coords 116 if (!newColor2.equals(Color.RED)) { 117 System.err.println("newColor2 = " + newColor2); 118 throw new RuntimeException("Test FAILED: frame pixel at (100, 100) is not red (transparent?)"); 119 } 120 121 System.out.println("Test PASSED"); 122 } 123 } |