Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Paint/PaintNativeOnUpdate.java
47490 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.AWTException;24import java.awt.Color;25import java.awt.Component;26import java.awt.Frame;27import java.awt.Graphics;28import java.awt.Label;29import java.awt.Point;3031/**32* @test33* @bug 715768034* @library ../../../lib/testlibrary35* @build ExtendedRobot36* @author Sergey Bylokhov37@ @run main PaintNativeOnUpdate38*/39public final class PaintNativeOnUpdate extends Label {4041private boolean fullUpdate = true;4243public static void main(final String[] args) throws AWTException {44ExtendedRobot robot = new ExtendedRobot();45robot.setAutoDelay(50);46final Frame frame = new Frame();47final Component label = new PaintNativeOnUpdate();48frame.setBackground(Color.RED);49frame.add(label);50frame.setSize(300, 300);51frame.setUndecorated(true);52frame.setLocationRelativeTo(null);53frame.setVisible(true);54robot.waitForIdle(1000);55label.repaint();// first paint56robot.waitForIdle(1000);57label.repaint();// incremental paint58robot.waitForIdle(1000);5960Point point = label.getLocationOnScreen();61Color color = robot.getPixelColor(point.x + label.getWidth() / 2,62point.y + label.getHeight() / 2);63if (!color.equals(Color.GREEN)) {64System.err.println("Expected color = " + Color.GREEN);65System.err.println("Actual color = " + color);66throw new RuntimeException();67}68frame.dispose();69}7071@Override72public void update(final Graphics g) {73if (fullUpdate) {74//full paint75g.setColor(Color.GREEN);76g.fillRect(0, 0, getWidth(), getHeight());77fullUpdate = false;78} else {79// Do nothing80// incremental paint81}82}8384@Override85public void paint(final Graphics g) {86// Do nothing87}88}899091