Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/NativeInLightShow/NativeInLightShow.java
47311 views
/*1* Copyright (c) 2004, 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*/2223/*24@test 1.0 04/05/2025@bug 414048426@summary Heavyweight components inside invisible lightweight containers still show27@author Your Name: [email protected]28@run main NativeInLightShow29*/3031import java.awt.*;32import java.awt.event.*;333435// The test verifies that the mixing code correctly handles COMPONENT_SHOWN events36// while the top-level container is invisible.3738public class NativeInLightShow39{40//Declare things used in the test, like buttons and labels here41static boolean buttonPressed = false;42public static void main(String args[]) throws Exception {43Frame f = new Frame("Test");4445Robot robot = null;46robot = new Robot();47robot.setAutoDelay(50);4849Container c = new Container();50c.setLayout(new BorderLayout());51Button b = new Button("I'm should be visible!");52b.addActionListener(new ActionListener()53{54public void actionPerformed(ActionEvent e) {55System.out.println("Test PASSED");56buttonPressed = true;57}58});59c.add(b);6061f.add(c);6263f.pack();6465c.setVisible(false);66c.setVisible(true);6768// Wait for a while for COMPONENT_SHOW event to be dispatched69robot.waitForIdle();7071f.setVisible(true);7273robot.waitForIdle();7475Point buttonLocation = b.getLocationOnScreen();7677robot.mouseMove(buttonLocation.x + 5, buttonLocation.y + 5);78robot.mousePress(InputEvent.BUTTON1_MASK);79robot.mouseRelease(InputEvent.BUTTON1_MASK);8081// Wait for a while for ACTION event to be dispatched82robot.waitForIdle();83robot.delay(100);8485if (!buttonPressed) {86System.out.println("Test FAILED");87throw new RuntimeException("Button was not pressed");88}89}9091}929394