Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/FocusEmbeddedFrameTest/FocusEmbeddedFrameTest.java
47525 views
/*1* Copyright (c) 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/*24@test25@bug 651667526@summary Tests that EmbeddedFrame can be focused.27@author anton.tarasov: area=awt-focus28@library ../../regtesthelpers29@build Util UtilInternal30@run main FocusEmbeddedFrameTest31*/3233import java.awt.*;34import java.awt.event.*;35import java.applet.Applet;36import java.util.concurrent.atomic.AtomicBoolean;37import java.lang.reflect.InvocationTargetException;38import test.java.awt.regtesthelpers.Util;39import test.java.awt.regtesthelpers.UtilInternal;4041public class FocusEmbeddedFrameTest extends Applet {42static Frame embedder = new Frame("Embedder");43static Frame ef = null;44static volatile boolean passed;4546Robot robot;4748public static void main(String[] args) {49FocusEmbeddedFrameTest app = new FocusEmbeddedFrameTest();50app.init();51app.start();52}5354public void init() {55robot = Util.createRobot();56}5758public void start() {5960if (!"sun.awt.windows.WToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {61System.out.println("The test is for WToolkit only!");62return;63}6465Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {66public void eventDispatched(AWTEvent e) {67System.err.println("--> " + e);68}69}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_EVENT_MASK);7071embedder.addNotify();7273try {74ef = UtilInternal.createEmbeddedFrame(embedder);75} catch (Throwable t) {76t.printStackTrace();77throw new Error("Test error: couldn't create an EmbeddedFrame!");78}7980ef.setSize(100, 100);81ef.setBackground(Color.blue);8283embedder.addFocusListener(new FocusAdapter() {84public void focusGained(FocusEvent e) {85FocusEmbeddedFrameTest.ef.requestFocus();86}87});8889ef.addFocusListener(new FocusAdapter() {90public void focusGained(FocusEvent e) {91passed = true;92}93});9495embedder.setSize(150, 150);96embedder.setVisible(true);9798Util.waitForIdle(robot);99100if (!passed) {101throw new TestFailedException("the EmbeddedFrame didn't get focus on request!");102}103104System.out.println("Test passed.");105}106}107108class TestFailedException extends RuntimeException {109TestFailedException(String msg) {110super("Test failed: " + msg);111}112}113114115