Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Frame/ShownOnPack/ShownOnPack.java
41153 views
1
/*
2
* Copyright (c) 2007, 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 6525850
27
@summary Iconified frame gets shown after pack()
28
@author anthony.petrov@...: area=awt.toplevel
29
@run applet/manual=yesno ShownOnPack.html
30
*/
31
32
33
/**
34
* ShownOnPack.java
35
*
36
* summary:
37
*/
38
39
import java.applet.Applet;
40
import java.awt.*;
41
42
public class ShownOnPack extends Applet
43
{
44
//Declare things used in the test, like buttons and labels here
45
Frame f;
46
47
public void init()
48
{
49
//Create instructions for the user here, as well as set up
50
// the environment -- set the layout manager, add buttons,
51
// etc.
52
this.setLayout (new BorderLayout ());
53
54
String[] instructions =
55
{
56
"This test creates an invisible and iconified frame that should not become visible.",
57
"If you observe the window titled 'Should NOT BE SHOWN' in the taskbar, press FAIL,",
58
"else press PASS"
59
};
60
Sysout.createDialogWithInstructions( instructions );
61
62
}//End init()
63
64
public void start ()
65
{
66
//Get things going. Request focus, set size, et cetera
67
setSize (200,200);
68
setVisible(true);
69
validate();
70
71
//What would normally go into main() will probably go here.
72
//Use System.out.println for diagnostic messages that you want
73
// to read after the test is done.
74
//Use Sysout.println for messages you want the tester to read.
75
f = new Frame("Should NOT BE SHOWN");
76
f.setExtendedState(Frame.ICONIFIED);
77
f.pack();
78
}// start()
79
80
//The rest of this class is the actions which perform the test...
81
82
//Use Sysout.println to communicate with the user NOT System.out!!
83
//Sysout.println ("Something Happened!");
84
85
}// class ShownOnPack
86
87
/* Place other classes related to the test after this line */
88
89
90
91
92
93
/****************************************************
94
Standard Test Machinery
95
DO NOT modify anything below -- it's a standard
96
chunk of code whose purpose is to make user
97
interaction uniform, and thereby make it simpler
98
to read and understand someone else's test.
99
****************************************************/
100
101
/**
102
This is part of the standard test machinery.
103
It creates a dialog (with the instructions), and is the interface
104
for sending text messages to the user.
105
To print the instructions, send an array of strings to Sysout.createDialog
106
WithInstructions method. Put one line of instructions per array entry.
107
To display a message for the tester to see, simply call Sysout.println
108
with the string to be displayed.
109
This mimics System.out.println but works within the test harness as well
110
as standalone.
111
*/
112
113
class Sysout
114
{
115
private static TestDialog dialog;
116
117
public static void createDialogWithInstructions( String[] instructions )
118
{
119
dialog = new TestDialog( new Frame(), "Instructions" );
120
dialog.printInstructions( instructions );
121
dialog.setVisible(true);
122
println( "Any messages for the tester will display here." );
123
}
124
125
public static void createDialog( )
126
{
127
dialog = new TestDialog( new Frame(), "Instructions" );
128
String[] defInstr = { "Instructions will appear here. ", "" } ;
129
dialog.printInstructions( defInstr );
130
dialog.setVisible(true);
131
println( "Any messages for the tester will display here." );
132
}
133
134
135
public static void printInstructions( String[] instructions )
136
{
137
dialog.printInstructions( instructions );
138
}
139
140
141
public static void println( String messageIn )
142
{
143
dialog.displayMessage( messageIn );
144
}
145
146
}// Sysout class
147
148
/**
149
This is part of the standard test machinery. It provides a place for the
150
test instructions to be displayed, and a place for interactive messages
151
to the user to be displayed.
152
To have the test instructions displayed, see Sysout.
153
To have a message to the user be displayed, see Sysout.
154
Do not call anything in this dialog directly.
155
*/
156
class TestDialog extends Dialog
157
{
158
159
TextArea instructionsText;
160
TextArea messageText;
161
int maxStringLength = 80;
162
163
//DO NOT call this directly, go through Sysout
164
public TestDialog( Frame frame, String name )
165
{
166
super( frame, name );
167
int scrollBoth = TextArea.SCROLLBARS_BOTH;
168
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
169
add( "North", instructionsText );
170
171
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
172
add("Center", messageText);
173
174
pack();
175
176
setVisible(true);
177
}// TestDialog()
178
179
//DO NOT call this directly, go through Sysout
180
public void printInstructions( String[] instructions )
181
{
182
//Clear out any current instructions
183
instructionsText.setText( "" );
184
185
//Go down array of instruction strings
186
187
String printStr, remainingStr;
188
for( int i=0; i < instructions.length; i++ )
189
{
190
//chop up each into pieces maxSringLength long
191
remainingStr = instructions[ i ];
192
while( remainingStr.length() > 0 )
193
{
194
//if longer than max then chop off first max chars to print
195
if( remainingStr.length() >= maxStringLength )
196
{
197
//Try to chop on a word boundary
198
int posOfSpace = remainingStr.
199
lastIndexOf( ' ', maxStringLength - 1 );
200
201
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
202
203
printStr = remainingStr.substring( 0, posOfSpace + 1 );
204
remainingStr = remainingStr.substring( posOfSpace + 1 );
205
}
206
//else just print
207
else
208
{
209
printStr = remainingStr;
210
remainingStr = "";
211
}
212
213
instructionsText.append( printStr + "\n" );
214
215
}// while
216
217
}// for
218
219
}//printInstructions()
220
221
//DO NOT call this directly, go through Sysout
222
public void displayMessage( String messageIn )
223
{
224
messageText.append( messageIn + "\n" );
225
System.out.println(messageIn);
226
}
227
228
}// TestDialog class
229
230