// (Don't use black, since a failed sample is sometimes black)
final Color BACKGROUND = Color.GREEN;
final Color FOREGROUND = Color.RED;
back.setBackground(BACKGROUND);
back.setLocation(X, Y);
final JWindow front = new JWindow(root);
front.getContentPane().setBackground(FOREGROUND);
front.setLocation(X, Y);
Area mask = new Area(new Rectangle(0, 0, W, H));
mask.subtract(new Area(new Rectangle(W/4, H/4, W/2, H/2)));
WindowUtils.setWindowMask(front, mask);
front.addMouseListener(handler);
front.addMouseMotionListener(handler);
SwingUtilities.invokeAndWait(new Runnable() { public void run() {
back.pack();
back.setSize(new Dimension(W, H));
back.setVisible(true);
front.pack();
front.setSize(new Dimension(W, H));
front.setVisible(true);
}});
Point where = front.getLocationOnScreen();
where.translate(W/8, H/8);
Color sample = robot.getPixelColor(where.x, where.y);
long start = System.currentTimeMillis();
while (!sample.equals(FOREGROUND)) {
SwingUtilities.invokeAndWait(new Runnable() { public void run() {
front.toFront();
}});
Thread.sleep(10);
if (System.currentTimeMillis() - start > 5000)
fail("Timed out waiting for shaped window to appear, "
+ "expected foreground color (sample="
+ sample + " vs expected=" + FOREGROUND + ")");
sample = robot.getPixelColor(where.x, where.y);
}
where = front.getLocationOnScreen();
where.translate(W/2, H/2);
sample = robot.getPixelColor(where.x, where.y);
start = System.currentTimeMillis();
while (!sample.equals(BACKGROUND)) {
Thread.sleep(10);