Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/Revalidate/Revalidate.java
47661 views
/*1* Copyright (c) 2011, 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*/2223/*24@test25@bug 703666926@summary Test Component.revalidate() method27@author [email protected]: area=awt.component28@run main/othervm -Djava.awt.smartInvalidate=true Revalidate29*/3031import java.awt.*;3233public class Revalidate {34private static Frame frame = new Frame();35private static Panel panel = new Panel() {36@Override37public boolean isValidateRoot() {38return true;39}40};41private static Button button = new Button("Test");4243private static void sleep() {44try { Thread.sleep(500); } catch (Exception e) {}45}4647private static void printState(String str) {48System.out.println(str + " isValid state: ");49System.out.println(" frame: " + frame.isValid());50System.out.println(" panel: " + panel.isValid());51System.out.println(" button: " + button.isValid());52}5354private static void fail(String msg) {55frame.dispose();56throw new RuntimeException(msg);57}5859private static void check(String n, Component c, boolean v) {60if (c.isValid() != v) {61fail(n + ".isValid() = " + c.isValid() + "; expected: " + v);62}63}64private static void check(String str, boolean f, boolean p, boolean b) {65printState(str);6667check("frame", frame, f);68check("panel", panel, p);69check("button", button, b);70}7172public static void main(String[] args) {73// setup74frame.add(panel);75panel.add(button);76frame.setBounds(200, 200, 300, 200);77frame.setVisible(true);78sleep();79check("Upon showing", true, true, true);8081button.setBounds(1, 1, 30, 30);82sleep();83check("button.setBounds():", true, false, false);8485button.revalidate();86sleep();87check("button.revalidate():", true, true, true);8889button.setBounds(1, 1, 30, 30);90sleep();91check("button.setBounds():", true, false, false);9293panel.revalidate();94sleep();95// because the panel's validate root is actually OK96check("panel.revalidate():", true, false, false);9798button.revalidate();99sleep();100check("button.revalidate():", true, true, true);101102panel.setBounds(2, 2, 125, 130);103sleep();104check("panel.setBounds():", false, false, true);105106button.revalidate();107sleep();108check("button.revalidate():", false, true, true);109110panel.setBounds(3, 3, 152, 121);111sleep();112check("panel.setBounds():", false, false, true);113114panel.revalidate();115sleep();116check("panel.revalidate():", true, true, true);117118// cleanup119frame.dispose();120}121}122123124