Path: blob/master/test/jdk/java/awt/Focus/6981400/Test2.java
41153 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* @key headful26* @bug 698140027* @summary Tabbing between textfiled do not work properly when ALT+TAB28* @author anton.tarasov29* @library ../../regtesthelpers30* @build Util31* @run main Test232*/3334// A focus request made after a char is typed ahead shouldn't affect the char's target component.3536import java.awt.*;37import java.awt.event.*;38import test.java.awt.regtesthelpers.Util;3940public class Test2 {41static Frame f = new Frame("frame");42static TextArea t0 = new TextArea(1, 10) { public String toString() { return "[TA-0]";} };43static TextArea t1 = new TextArea(1, 10) { public String toString() { return "[TA-1]";} };44static TextArea t2 = new TextArea(1, 10) { public String toString() { return "[TA-2]";} };4546static volatile boolean passed = true;4748static Robot robot;4950public static void main(String[] args) {51Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {52public void eventDispatched(AWTEvent e) {53System.out.println(e);54if (e.getID() == KeyEvent.KEY_TYPED) {55if (e.getSource() != t1) {56passed = false;57throw new RuntimeException("Test failed: the key event has wrong source: " + e);58}59}60}61}, FocusEvent.FOCUS_EVENT_MASK | KeyEvent.KEY_EVENT_MASK);6263try {64robot = new Robot();65} catch (AWTException ex) {66throw new RuntimeException("Error: can't create Robot");67}6869f.add(t0);70f.add(t1);71f.add(t2);7273f.setLayout(new FlowLayout());74f.pack();7576t0.addFocusListener(new FocusAdapter() {77public void focusLost(FocusEvent e) {78try {79Thread.sleep(3000);80} catch (Exception ex) {}81}82});8384// The request shouldn't affect the key event delivery.85new Thread(new Runnable() {86public void run() {87try {88Thread.sleep(2000);89} catch (Exception ex) {}90System.out.println("requesting focus to " + t2);91t2.requestFocus();92}93}).start();949596f.setVisible(true);97Util.waitForIdle(robot);9899test();100101if (passed) System.out.println("\nTest passed.");102}103104static void test() {105Util.clickOnComp(t1, robot);106107// The key event should be eventually delivered to t1.108robot.delay(50);109robot.keyPress(KeyEvent.VK_A);110robot.delay(50);111robot.keyRelease(KeyEvent.VK_A);112113Util.waitForIdle(robot);114}115}116117118119