Path: blob/master/test/jdk/java/awt/Modal/MultipleDialogs/MixOfModalAndNonModalDialogs.java
41153 views
/*1* Copyright (c) 2018, 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*/2223import java.awt.Dialog;24import java.awt.Frame;25import java.util.concurrent.CountDownLatch;2627/**28* @test29* @key headful30* @bug 821520031* @summary tests mixing of modal and non-modal dialogs32*/33public final class MixOfModalAndNonModalDialogs {3435public static void main(final String[] args) throws Exception {36final Frame frame = new Frame();37try {38frame.setSize(300, 300);39frame.setLocationRelativeTo(null);40frame.setVisible(true);4142// mix of modal, non-modal and invisible dialogs, all combinations43for (int step = 0; step < 3; ++step) {44for (int i = 0; i < 10; ++i) {45showDialog(frame, i);46}47showModalDialog(frame);48for (int i = 0; i < 10; ++i) {49showDialog(frame, i);50}51}52} finally {53frame.dispose();54}55}5657private static void showDialog(final Frame frame, final int i) {58final Dialog visible = new Dialog(frame);59visible.setLocationRelativeTo(null);60visible.setVisible(true);61if (i % 2 == 0) {62new Dialog(frame);63}64}6566private static void showModalDialog(final Frame frame) throws Exception {67final CountDownLatch go = new CountDownLatch(1);68final Thread thread = new Thread(() -> {69final Dialog modal = new Dialog(frame, "Modal Dialog", true);70modal.pack();71go.countDown();72modal.setLocationRelativeTo(null);73modal.setVisible(true);74});75thread.start();76go.await();77}78}798081