test/java/awt/Window/BackgroundIsNotUpdated/BackgroundIsNotUpdated.java
Print this page
*** 25,44 ****
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Robot;
- import java.awt.Toolkit;
import java.awt.Window;
- import sun.awt.SunToolkit;
-
/**
* @test
* @bug 8001472
* @summary Background of the window should not depend from the paint()/update()
* @author Sergey Bylokhov
*/
public final class BackgroundIsNotUpdated extends Window {
public BackgroundIsNotUpdated(final Frame owner) {
super(owner);
--- 25,44 ----
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Window;
/**
* @test
* @bug 8001472
* @summary Background of the window should not depend from the paint()/update()
* @author Sergey Bylokhov
+ * @library ../../../../lib/testlibrary
+ * @build ExtendedRobot
+ * @run main BackgroundIsNotUpdated
*/
public final class BackgroundIsNotUpdated extends Window {
public BackgroundIsNotUpdated(final Frame owner) {
super(owner);
*** 57,84 ****
public static void main(final String[] args) throws AWTException {
final Window window = new BackgroundIsNotUpdated(null);
window.setSize(300, 300);
window.setLocationRelativeTo(null);
window.setVisible(true);
! sleep();
! window.setBackground(Color.GREEN);
! sleep();
! final Robot robot = new Robot();
robot.setAutoDelay(200);
Point point = window.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
point.y + window.getHeight() / 2);
window.dispose();
if (!color.equals(Color.GREEN)) {
throw new RuntimeException(
"Expected: " + Color.GREEN + " , Actual: " + color);
}
}
-
- private static void sleep() {
- try {
- ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
- Thread.sleep(1000);
- } catch (InterruptedException ignored) {
- }
- }
}
--- 57,77 ----
public static void main(final String[] args) throws AWTException {
final Window window = new BackgroundIsNotUpdated(null);
window.setSize(300, 300);
window.setLocationRelativeTo(null);
window.setVisible(true);
! window.requestFocus();
! final ExtendedRobot robot = new ExtendedRobot();
robot.setAutoDelay(200);
+ robot.waitForIdle(1000);
+ window.setBackground(Color.GREEN);
+ robot.waitForIdle(1000);
Point point = window.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
point.y + window.getHeight() / 2);
window.dispose();
if (!color.equals(Color.GREEN)) {
throw new RuntimeException(
"Expected: " + Color.GREEN + " , Actual: " + color);
}
}
}