Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Container/MoveToOtherScreenTest/MoveToOtherScreenTest.java
38828 views
/*1* Copyright (c) 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*/2223import javax.swing.JFrame;24import javax.swing.SwingUtilities;25import java.awt.Canvas;26import java.awt.Color;27import java.awt.Dimension;28import java.awt.Frame;29import java.awt.GraphicsConfiguration;30import java.awt.GraphicsDevice;31import java.awt.GraphicsEnvironment;32import java.lang.reflect.InvocationTargetException;33343536/* @test37@bug 816069638@summary IllegalArgumentException: adding a component to a container on a different GraphicsDevice39@author Mikhail Cherkasov40@run main MoveToOtherScreenTest41*/42public class MoveToOtherScreenTest {4344private static volatile boolean twoDisplays = true;45private static final Canvas canvas = new Canvas();46private static final Frame[] frms = new JFrame[2];4748public static void main(String[] args) throws InterruptedException, InvocationTargetException {49SwingUtilities.invokeAndWait(new Runnable() {50public void run() {51GraphicsEnvironment ge = GraphicsEnvironment.52getLocalGraphicsEnvironment();53GraphicsDevice[] gds = ge.getScreenDevices();54if (gds.length < 2) {55System.out.println("Test requires at least 2 displays");56twoDisplays = false;57return;58}59for (int i = 0; i < 2; i++) {60GraphicsConfiguration conf = gds[i].getConfigurations()[0];61JFrame frm = new JFrame("Frame " + i);62frm.setLocation(conf.getBounds().x, 0); // On first screen63frm.setSize(new Dimension(400, 400));64frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);65frm.setVisible(true);66frms[i] = frm;67}68canvas.setBackground(Color.red);69frms[0].add(canvas);70}71});72if(!twoDisplays){73return;74}75Thread.sleep(200);76SwingUtilities.invokeAndWait(new Runnable() {77@Override78public void run() {79frms[1].add(canvas);80}81});82for (Frame frm : frms) {83frm.dispose();84}85}86}878889