Path: blob/master/test/jdk/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
66645 views
/*1* Copyright (c) 2006, 2021, 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 648053427@summary A Frame changing its state from ICONIFIED to NORMAL should regain focus.28@library ../../regtesthelpers29@build Util30@run main DeiconifiedFrameLoosesFocus31*/3233import java.awt.Frame;34import java.awt.Robot;35import java.awt.Toolkit;36import test.java.awt.regtesthelpers.Util;3738public class DeiconifiedFrameLoosesFocus {39Robot robot;40static final Frame frame = new Frame("Frame");4142public static void main(String[] args) {43DeiconifiedFrameLoosesFocus app = new DeiconifiedFrameLoosesFocus();44app.init();45try {46app.start();47} finally {48frame.dispose();49}50}5152public void init() {53robot = Util.createRobot();54}5556public void start() {57if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED) ||58!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.NORMAL))59{60System.out.println("Frame.ICONIFIED or Frame.NORMAL state is unsupported.");61return;62}6364frame.setSize(100, 100);6566frame.setVisible(true);6768Util.waitForIdle(robot);69robot.delay(1000);7071if (!frame.isFocused()) {72Util.clickOnTitle(frame, robot);73Util.waitForIdle(robot);74}7576if (!frame.isFocused()) {77throw new Error("Test error: couldn't focus the Frame.");78}7980test();81System.out.println("Test passed.");82}8384void test() {85frame.setExtendedState(Frame.ICONIFIED);8687Util.waitForIdle(robot);88robot.delay(500);8990frame.setExtendedState(Frame.NORMAL);9192Util.waitForIdle(robot);93robot.delay(500);9495if (!frame.isFocused()) {96throw new TestFailedException("the Frame didn't regain focus after restoring!");97}98}99}100101class TestFailedException extends RuntimeException {102TestFailedException(String msg) {103super("Test failed: " + msg);104}105}106107108