Path: blob/master/test/jdk/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
41153 views
/*1* Copyright (c) 2006, 2018, 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.*;34import test.java.awt.regtesthelpers.Util;3536public class DeiconifiedFrameLoosesFocus {37Robot robot;38static final Frame frame = new Frame("Frame");3940public static void main(String[] args) {41DeiconifiedFrameLoosesFocus app = new DeiconifiedFrameLoosesFocus();42app.init();43app.start();44}4546public void init() {47robot = Util.createRobot();48}4950public void start() {51if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED) ||52!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.NORMAL))53{54System.out.println("Frame.ICONIFIED or Frame.NORMAL state is unsupported.");55return;56}5758frame.setSize(100, 100);5960frame.setVisible(true);6162Util.waitForIdle(robot);6364if (!frame.isFocused()) {65Util.clickOnTitle(frame, robot);66Util.waitForIdle(robot);67}6869if (!frame.isFocused()) {70throw new Error("Test error: couldn't focus the Frame.");71}7273test();74System.out.println("Test passed.");75}7677void test() {78frame.setExtendedState(Frame.ICONIFIED);7980Util.waitForIdle(robot);8182frame.setExtendedState(Frame.NORMAL);8384Util.waitForIdle(robot);8586if (!frame.isFocused()) {87throw new TestFailedException("the Frame didn't regain focus after restoring!");88}89}90}9192class TestFailedException extends RuntimeException {93TestFailedException(String msg) {94super("Test failed: " + msg);95}96}979899