jdk/test/java/awt/Container/CheckZOrderChange/CheckZOrderChange.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8135 5143a1ab97f4
child 40128 e635645d2a8a
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8135
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8135
diff changeset
     2
 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
8135
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     4
 *
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     7
 * published by the Free Software Foundation.
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     8
 *
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    13
 * accompanied this code).
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    14
 *
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    18
 *
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    21
 * questions.
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    22
 */
5143a1ab97f4 7015232: missing copyright header in CheckZOrderChange.java
andrew
parents: 1172
diff changeset
    23
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    24
/*
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    25
   @test %I% %E%
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    26
   @bug 2161766
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    27
   @summary Component is missing after changing the z-order of the component & focus is not transfered in
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    28
   @author  Andrei Dmitriev : area=awt.container
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    29
   @run main CheckZOrderChange
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    30
*/
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    31
import java.awt.*;
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    32
import java.awt.event.*;
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    33
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    34
public class CheckZOrderChange {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    35
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    36
    private static Button content[] = new Button[]{new Button("Button 1"), new Button("Button 2"), new Button("Button 3"), new Button("Button 4")};
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    37
    private static Frame frame;
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    38
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    39
    public static void main(String[] args) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    40
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    41
        frame = new Frame("Test Frame");
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    42
        frame.setLayout(new FlowLayout());
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    43
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    44
        for (Button b: content){
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    45
            frame.add(b);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    46
        }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    47
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    48
        frame.setSize(300, 300);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    49
        frame.setVisible(true);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    50
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    51
        /* INITIAL ZORDERS ARE*/
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    52
        for (Button b: content){
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    53
            System.out.println("frame.getComponentZOrder("+ b +") = " + frame.getComponentZOrder(b));
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    54
        }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    55
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    56
        //Change the Z Order
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    57
        frame.setComponentZOrder(content[0], 2);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    58
        System.out.println("ZOrder of button1 changed to 2");
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    59
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    60
        if (frame.getComponentZOrder(content[0]) != 2 ||
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    61
            frame.getComponentZOrder(content[1]) != 0 ||
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    62
            frame.getComponentZOrder(content[2]) != 1 ||
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    63
            frame.getComponentZOrder(content[3]) != 3)
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    64
        {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    65
            for (Button b: content){
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    66
                System.out.println("frame.getComponentZOrder("+ b +") = " + frame.getComponentZOrder(b));
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    67
            }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    68
            throw new RuntimeException("TEST FAILED: getComponentZOrder did not return the correct value");
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    69
        }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    70
    }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents:
diff changeset
    71
}