Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
48073 views
/*1* Copyright (c) 2006, 2007, 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/*24test25@bug 648053426@summary A Frame changing its state from ICONIFIED to NORMAL should regain focus.27@author anton.tarasov@...: area=awt.focus28@run applet DeiconifiedFrameLoosesFocus.html29*/3031import java.awt.*;32import java.applet.Applet;33import test.java.awt.regtesthelpers.Util;3435public class DeiconifiedFrameLoosesFocus extends Applet {36Robot robot;37static final Frame frame = new Frame("Frame");3839public static void main(String[] args) {40DeiconifiedFrameLoosesFocus app = new DeiconifiedFrameLoosesFocus();41app.init();42app.start();43}4445public void init() {46robot = Util.createRobot();4748// Create instructions for the user here, as well as set up49// the environment -- set the layout manager, add buttons,50// etc.51this.setLayout (new BorderLayout ());52}5354public void start() {55if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED) ||56!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.NORMAL))57{58System.out.println("Frame.ICONIFIED or Frame.NORMAL state is unsupported.");59return;60}6162frame.setSize(100, 100);6364frame.setVisible(true);6566Util.waitForIdle(robot);6768if (!frame.isFocused()) {69Util.clickOnTitle(frame, robot);70Util.waitForIdle(robot);71}7273if (!frame.isFocused()) {74throw new Error("Test error: couldn't focus the Frame.");75}7677test();78System.out.println("Test passed.");79}8081void test() {82frame.setExtendedState(Frame.ICONIFIED);8384Util.waitForIdle(robot);8586frame.setExtendedState(Frame.NORMAL);8788Util.waitForIdle(robot);8990if (!frame.isFocused()) {91throw new TestFailedException("the Frame didn't regain focus after restoring!");92}93}94}9596class TestFailedException extends RuntimeException {97TestFailedException(String msg) {98super("Test failed: " + msg);99}100}101102103