Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/FullScreen/AllFramesMaximize/AllFramesMaximize.java
41154 views
1
/*
2
* Copyright (c) 2018, 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
/**
25
* @test
26
* @bug 8190767
27
* @key headful
28
* @requires os.family == "mac"
29
* @summary If JFrame is maximized on OS X, all new JFrames will be maximized by default
30
* @compile AllFramesMaximize.java
31
* @run main/manual AllFramesMaximize
32
*/
33
34
import javax.swing.JFrame;
35
import javax.swing.JButton;
36
import javax.swing.JTextArea;
37
import javax.swing.SwingUtilities;
38
import java.awt.FlowLayout;
39
import java.awt.event.ActionEvent;
40
import java.awt.event.ActionListener;
41
42
public class AllFramesMaximize {
43
private static JButton passButton;
44
private static JButton failButton;
45
private static JTextArea instructions;
46
private static JFrame mainFrame;
47
private static JFrame instructionFrame;
48
public static boolean isProgInterruption = false;
49
static Thread mainThread = null;
50
static int sleepTime = 300000;
51
52
public static void createAndShowJFrame() {
53
passButton = new JButton("Pass");
54
passButton.setEnabled(true);
55
56
failButton = new JButton("Fail");
57
failButton.setEnabled(true);
58
59
instructions = new JTextArea(8, 30);
60
instructions.setText(" This is a manual test\n\n" +
61
" 1) Click on the maximize button, JFrame will enter fullscreen\n" +
62
" 2) Click anywhere on the JFrame\n" +
63
" 3) Press Pass if new JFrame didn't open in fullscreen,\n" +
64
" 4) Press Fail if new JFrame opened in fullscreen");
65
66
instructionFrame = new JFrame("Test Instructions");
67
instructionFrame.setLocationRelativeTo(null);
68
instructionFrame.add(passButton);
69
instructionFrame.add(failButton);
70
instructionFrame.add(instructions);
71
instructionFrame.setSize(200,200);
72
instructionFrame.setLayout(new FlowLayout());
73
instructionFrame.pack();
74
instructionFrame.setVisible(true);
75
76
passButton.addActionListener(new ActionListener() {
77
@Override
78
public void actionPerformed(ActionEvent ae) {
79
dispose();
80
isProgInterruption = true;
81
mainThread.interrupt();
82
}
83
});
84
85
failButton.addActionListener(new ActionListener() {
86
@Override
87
public void actionPerformed(ActionEvent ae) {
88
dispose();
89
isProgInterruption = true;
90
mainThread.interrupt();
91
throw new RuntimeException("New JFrame opened on a new window!");
92
}
93
});
94
95
mainFrame = new JFrame();
96
JButton button = new JButton("Open Frame");
97
mainFrame.getContentPane().add(button);
98
button.addActionListener(
99
new ActionListener() {
100
public void actionPerformed(ActionEvent e) {
101
JFrame f = new JFrame();
102
f.setSize(400, 400);
103
f.setVisible(true);
104
}
105
});
106
mainFrame.setSize(500, 500);
107
mainFrame.setVisible(true);
108
}
109
110
private static void dispose() {
111
mainFrame.dispose();
112
instructionFrame.dispose();
113
}
114
115
public static void main(String[] args) throws Exception {
116
mainThread = Thread.currentThread();
117
SwingUtilities.invokeAndWait(AllFramesMaximize::createAndShowJFrame);
118
119
try {
120
mainThread.sleep(sleepTime);
121
} catch (InterruptedException e) {
122
if (!isProgInterruption) {
123
throw e;
124
}
125
} finally {
126
SwingUtilities.invokeAndWait(AllFramesMaximize::dispose);
127
}
128
129
if (!isProgInterruption) {
130
throw new RuntimeException("Timed out after " + sleepTime / 1000
131
+ " seconds");
132
}
133
}
134
}
135
136
137