Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/RemoveAfterRequest/RemoveAfterRequest.java
47490 views
/*1* Copyright (c) 2009, 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@bug 641140626@summary Components automatically transfer focus on removal, even if developer requests focus elsewhere first27@author oleg.sukhodolsky, anton.tarasov: area=awt.focus28@library ../../regtesthelpers29@build Util30@run main RemoveAfterRequest31*/3233/**34* RemoveAfterRequest.java35*36* summary: Components automatically transfer focus on removal, even if developer requests focus elsewhere first37*/3839import java.awt.*;40import java.awt.event.*;41import test.java.awt.regtesthelpers.Util;4243public class RemoveAfterRequest {44final static Frame frame = new Frame("test frame");45final static Button btn1 = new Button("btn1");46final static Button btn2 = new Button("btn2");47final static Button btn3 = new Button("btn3");4849public static void main(String[] args) {50frame.setLayout(new GridLayout(3, 1));51frame.add(btn1);52frame.add(btn2);53frame.add(btn3);54frame.pack();55frame.setVisible(true);5657Util.waitForIdle(null);5859if (!btn1.hasFocus()) {60btn1.requestFocus();61Util.waitForIdle(null);62if (!btn1.hasFocus()) {63throw new TestErrorException("couldn't focus " + btn1);64}65}6667if (!Util.trackFocusGained(btn3, new Runnable() {68public void run() {69btn3.requestFocus();70frame.remove(btn1);71frame.invalidate();72frame.validate();73frame.repaint();74}75}, 2000, true))76{77throw new TestFailedException("focus request on removal failed");78}7980System.out.println("Test passed.");81}82}8384/**85* Thrown when the behavior being verified is found wrong.86*/87class TestFailedException extends RuntimeException {88TestFailedException(String msg) {89super("Test failed: " + msg);90}91}9293/**94* Thrown when an error not related to the behavior being verified is encountered.95*/96class TestErrorException extends RuntimeException {97TestErrorException(String msg) {98super("Unexpected error: " + msg);99}100}101102103104