Path: blob/master/test/jdk/java/awt/Component/Revalidate/Revalidate.java
41153 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@key headful26@bug 703666927@summary Test Component.revalidate() method28@author [email protected]: area=awt.component29@run main/othervm -Djava.awt.smartInvalidate=true Revalidate30*/3132import java.awt.*;3334public class Revalidate {35private static Frame frame = new Frame();36private static Panel panel = new Panel() {37@Override38public boolean isValidateRoot() {39return true;40}41};42private static Button button = new Button("Test");4344private static void sleep() {45try { Thread.sleep(500); } catch (Exception e) {}46}4748private static void printState(String str) {49System.out.println(str + " isValid state: ");50System.out.println(" frame: " + frame.isValid());51System.out.println(" panel: " + panel.isValid());52System.out.println(" button: " + button.isValid());53}5455private static void fail(String msg) {56frame.dispose();57throw new RuntimeException(msg);58}5960private static void check(String n, Component c, boolean v) {61if (c.isValid() != v) {62fail(n + ".isValid() = " + c.isValid() + "; expected: " + v);63}64}65private static void check(String str, boolean f, boolean p, boolean b) {66printState(str);6768check("frame", frame, f);69check("panel", panel, p);70check("button", button, b);71}7273public static void main(String[] args) {74// setup75frame.add(panel);76panel.add(button);77frame.setBounds(200, 200, 300, 200);78frame.setVisible(true);79sleep();80check("Upon showing", true, true, true);8182button.setBounds(1, 1, 30, 30);83sleep();84check("button.setBounds():", true, false, false);8586button.revalidate();87sleep();88check("button.revalidate():", true, true, true);8990button.setBounds(1, 1, 30, 30);91sleep();92check("button.setBounds():", true, false, false);9394panel.revalidate();95sleep();96// because the panel's validate root is actually OK97check("panel.revalidate():", true, false, false);9899button.revalidate();100sleep();101check("button.revalidate():", true, true, true);102103panel.setBounds(2, 2, 125, 130);104sleep();105check("panel.setBounds():", false, false, true);106107button.revalidate();108sleep();109check("button.revalidate():", false, true, true);110111panel.setBounds(3, 3, 152, 121);112sleep();113check("panel.setBounds():", false, false, true);114115panel.revalidate();116sleep();117check("panel.revalidate():", true, true, true);118119// cleanup120frame.dispose();121}122}123124125