Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/6981400/Test2.java
48452 views
/*1* Copyright (c) 2012, 2013, 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 698140026* @summary Tabbing between textfiled do not work properly when ALT+TAB27* @author anton.tarasov28* @library ../../regtesthelpers29* @build Util30* @run main Test231*/3233// A focus request made after a char is typed ahead shouldn't affect the char's target component.3435import java.awt.*;36import java.awt.event.*;37import test.java.awt.regtesthelpers.Util;3839public class Test2 {40static Frame f = new Frame("frame");41static TextArea t0 = new TextArea(1, 10) { public String toString() { return "[TA-0]";} };42static TextArea t1 = new TextArea(1, 10) { public String toString() { return "[TA-1]";} };43static TextArea t2 = new TextArea(1, 10) { public String toString() { return "[TA-2]";} };4445static volatile boolean passed = true;4647static Robot robot;4849public static void main(String[] args) {50Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {51public void eventDispatched(AWTEvent e) {52System.out.println(e);53if (e.getID() == KeyEvent.KEY_TYPED) {54if (e.getSource() != t1) {55passed = false;56throw new RuntimeException("Test failed: the key event has wrong source: " + e);57}58}59}60}, FocusEvent.FOCUS_EVENT_MASK | KeyEvent.KEY_EVENT_MASK);6162try {63robot = new Robot();64} catch (AWTException ex) {65throw new RuntimeException("Error: can't create Robot");66}6768f.add(t0);69f.add(t1);70f.add(t2);7172f.setLayout(new FlowLayout());73f.pack();7475t0.addFocusListener(new FocusAdapter() {76public void focusLost(FocusEvent e) {77try {78Thread.sleep(3000);79} catch (Exception ex) {}80}81});8283// The request shouldn't affect the key event delivery.84new Thread(new Runnable() {85public void run() {86try {87Thread.sleep(2000);88} catch (Exception ex) {}89System.out.println("requesting focus to " + t2);90t2.requestFocus();91}92}).start();939495f.setVisible(true);96Util.waitForIdle(robot);9798test();99100if (passed) System.out.println("\nTest passed.");101}102103static void test() {104Util.clickOnComp(t1, robot);105106// The key event should be eventually delivered to t1.107robot.delay(50);108robot.keyPress(KeyEvent.VK_A);109robot.delay(50);110robot.keyRelease(KeyEvent.VK_A);111112Util.waitForIdle(robot);113}114}115116117118