Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Container/MoveToOtherScreenTest/MoveToOtherScreenTest.java
38828 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import javax.swing.JFrame;
25
import javax.swing.SwingUtilities;
26
import java.awt.Canvas;
27
import java.awt.Color;
28
import java.awt.Dimension;
29
import java.awt.Frame;
30
import java.awt.GraphicsConfiguration;
31
import java.awt.GraphicsDevice;
32
import java.awt.GraphicsEnvironment;
33
import java.lang.reflect.InvocationTargetException;
34
35
36
37
/* @test
38
@bug 8160696
39
@summary IllegalArgumentException: adding a component to a container on a different GraphicsDevice
40
@author Mikhail Cherkasov
41
@run main MoveToOtherScreenTest
42
*/
43
public class MoveToOtherScreenTest {
44
45
private static volatile boolean twoDisplays = true;
46
private static final Canvas canvas = new Canvas();
47
private static final Frame[] frms = new JFrame[2];
48
49
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
50
SwingUtilities.invokeAndWait(new Runnable() {
51
public void run() {
52
GraphicsEnvironment ge = GraphicsEnvironment.
53
getLocalGraphicsEnvironment();
54
GraphicsDevice[] gds = ge.getScreenDevices();
55
if (gds.length < 2) {
56
System.out.println("Test requires at least 2 displays");
57
twoDisplays = false;
58
return;
59
}
60
for (int i = 0; i < 2; i++) {
61
GraphicsConfiguration conf = gds[i].getConfigurations()[0];
62
JFrame frm = new JFrame("Frame " + i);
63
frm.setLocation(conf.getBounds().x, 0); // On first screen
64
frm.setSize(new Dimension(400, 400));
65
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
66
frm.setVisible(true);
67
frms[i] = frm;
68
}
69
canvas.setBackground(Color.red);
70
frms[0].add(canvas);
71
}
72
});
73
if(!twoDisplays){
74
return;
75
}
76
Thread.sleep(200);
77
SwingUtilities.invokeAndWait(new Runnable() {
78
@Override
79
public void run() {
80
frms[1].add(canvas);
81
}
82
});
83
for (Frame frm : frms) {
84
frm.dispose();
85
}
86
}
87
}
88
89