Path: blob/master/test/jdk/java/awt/Component/NativeInLightShow/NativeInLightShow.java
41154 views
/*1* Copyright (c) 2004, 2016, 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@key headful26@bug 414048427@summary Heavyweight components inside invisible lightweight containers still show28@author Your Name: [email protected]29@run main NativeInLightShow30*/3132import java.awt.*;33import java.awt.event.*;343536// The test verifies that the mixing code correctly handles COMPONENT_SHOWN events37// while the top-level container is invisible.3839public class NativeInLightShow40{41//Declare things used in the test, like buttons and labels here42static boolean buttonPressed = false;43public static void main(String args[]) throws Exception {44Frame f = new Frame("Test");4546Robot robot = null;47robot = new Robot();48robot.setAutoDelay(50);4950Container c = new Container();51c.setLayout(new BorderLayout());52Button b = new Button("I'm should be visible!");53b.addActionListener(new ActionListener()54{55public void actionPerformed(ActionEvent e) {56System.out.println("Test PASSED");57buttonPressed = true;58}59});60c.add(b);6162f.add(c);6364f.pack();6566c.setVisible(false);67c.setVisible(true);6869// Wait for a while for COMPONENT_SHOW event to be dispatched70robot.waitForIdle();7172f.setVisible(true);7374robot.waitForIdle();7576Point buttonLocation = b.getLocationOnScreen();7778robot.mouseMove(buttonLocation.x + 5, buttonLocation.y + 5);79robot.mousePress(InputEvent.BUTTON1_MASK);80robot.mouseRelease(InputEvent.BUTTON1_MASK);8182// Wait for a while for ACTION event to be dispatched83robot.waitForIdle();84robot.delay(100);8586if (!buttonPressed) {87System.out.println("Test FAILED");88throw new RuntimeException("Button was not pressed");89}90}9192}939495