Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Frame/GetBoundsResizeTest/GetBoundsResizeTest.java
41153 views
1
/*
2
* Copyright (c) 1998, 2014, 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
/* @test
25
@bug 4103095
26
@summary Test for getBounds() after a Frame resize.
27
@author andrei.dmitriev : area=awt.toplevel
28
@run main/manual GetBoundsResizeTest
29
*/
30
31
import java.applet.Applet;
32
import java.lang.*;
33
import java.awt.*;
34
import java.awt.event.*;
35
36
class Globals {
37
static boolean testPassed=false;
38
static Thread mainThread=null;
39
}
40
41
public class GetBoundsResizeTest extends Applet {
42
43
public static void main(String args[]) throws Exception {
44
GetBoundsResizeTest app = new GetBoundsResizeTest();
45
app.start();
46
Globals.mainThread = Thread.currentThread();
47
try {
48
Thread.sleep(300000);
49
} catch (InterruptedException e) {
50
if (!Globals.testPassed)
51
throw new Exception("GetBoundsResizeTest failed.");
52
}
53
}
54
55
public void start()
56
{
57
String[] message = {
58
"Resize the window using the upper left corner.",
59
"Press the button to print the result of getBounds() to the terminal.",
60
"If getBounds() prints the correct values for the window",
61
"then click Pass, else click Fail."
62
};
63
new TestDialog(new Frame(), "GetBoundsResizeTest", message).start();
64
new GetBoundsResizeTester("GetBoundsResizeTester").start();
65
}
66
}
67
68
////////////////////////////////////////////////////////////////////////
69
// Test Dialog
70
////////////////////////////////////////////////////////////////////////
71
72
class TestDialog extends Dialog
73
implements ActionListener {
74
75
static TextArea output;
76
Button passButton;
77
Button failButton;
78
String name;
79
80
public TestDialog(Frame frame, String name, String[] message)
81
{
82
super(frame, name + " Pass/Fail Dialog");
83
this.name = name;
84
int maxStringLength = 0;
85
for (int i=0; i<message.length; i++) {
86
maxStringLength = Math.max(maxStringLength, message[i].length());
87
}
88
output = new TextArea(10, maxStringLength);
89
add("North", output);
90
for (int i=0; i<message.length; i++){
91
output.append(message[i] + "\n");
92
}
93
Panel buttonPanel = new Panel();
94
passButton = new Button("Pass");
95
failButton = new Button("Fail");
96
passButton.addActionListener(this);
97
failButton.addActionListener(this);
98
buttonPanel.add(passButton);
99
buttonPanel.add(failButton);
100
add("South", buttonPanel);
101
pack();
102
}
103
104
public void start()
105
{
106
show();
107
}
108
109
public void actionPerformed(ActionEvent event)
110
{
111
if ( event.getSource() == passButton ) {
112
Globals.testPassed = true;
113
System.err.println(name + " Passed.");
114
}
115
else if ( event.getSource() == failButton ) {
116
Globals.testPassed = false;
117
System.err.println(name + " Failed.");
118
}
119
this.dispose();
120
if (Globals.mainThread != null)
121
Globals.mainThread.interrupt();
122
}
123
}
124
125
126
////////////////////////////////////////////////////////////////////////
127
// Test Class
128
////////////////////////////////////////////////////////////////////////
129
130
class GetBoundsResizeTester extends Frame {
131
Button b = new Button("Press");
132
133
GetBoundsResizeTester(String name)
134
{
135
super(name);
136
final Frame f = this;
137
Panel p = new Panel();
138
f.add(p);
139
p.setLayout(new BorderLayout());
140
b.addActionListener(new ActionListener() {
141
public void actionPerformed(ActionEvent be){
142
Point cp = b.getLocationOnScreen();
143
TestDialog.output.append("Current Frame.getBounds() = " + f.getBounds()+"\n");
144
}
145
});
146
p.add("Center", b);
147
f.pack();
148
}
149
150
public void start ()
151
{
152
setVisible(true);
153
Robot robot;
154
try {
155
robot = new Robot();
156
robot.waitForIdle();
157
}catch(Exception ignorex) {
158
}
159
Point cp = b.getLocationOnScreen();
160
TestDialog.output.append("Original Frame.getBounds() = " + this.getBounds()+"\n");
161
}
162
163
public static void main(String[] args)
164
{
165
new GetBoundsResizeTester("GetBoundsResizeTester").start();
166
}
167
168
}
169
170