Path: blob/master/test/jdk/java/awt/Focus/FocusTraversalPolicy/ContainerOrderFTPTest.java
41152 views
/*1* Copyright (c) 2016, 2016, 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 802500127@summary Tests java.awt.ContainerOrderFocusTraversalPolicy functionality.28@run main ContainerOrderFTPTest29*/3031import java.awt.Frame;32import java.awt.Button;33import java.awt.Component;34import java.awt.FlowLayout;35import java.awt.ContainerOrderFocusTraversalPolicy;3637public class ContainerOrderFTPTest {3839private final ContainerOrderFocusTraversalPolicy coftp;40private final Frame frame;41private final Button b1;42private final Button b2;43private final String expectedTraversal;4445public ContainerOrderFTPTest() {46expectedTraversal = "B1B2F1";47b1 = new Button("B1");48b2 = new Button("B2");49frame = new Frame("F1");5051frame.setLayout(new FlowLayout());52frame.setSize(200, 200);53coftp = new ContainerOrderFocusTraversalPolicy();54frame.setFocusTraversalPolicy(coftp);55frame.add(b1);56frame.add(b2);57frame.setVisible(true);58}5960public static void main(String[] args) throws Exception {61ContainerOrderFTPTest test = new ContainerOrderFTPTest();62test.performTest();63test.dispose();64}6566public void performTest() {67int count = 0;68Component comp = coftp.getFirstComponent(frame);69String traversal = "";70do {71comp = coftp.getComponentAfter(frame, comp);72if (comp instanceof Button) {73traversal += ((Button)comp).getLabel();74} else if (comp instanceof Frame) {75traversal += ((Frame)comp).getTitle();76}77count++;78} while(count < 3);7980if (!expectedTraversal.equals(traversal)) {81dispose();82throw new RuntimeException("Incorrect Traversal. Expected : "83+ expectedTraversal + "Actual : " + traversal);84}85}8687public void dispose() {88frame.dispose();89}90}919293