1
1
/*
2
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
20
20
* or visit www.oracle.com if you need additional information or have any
21
21
* questions.
22
22
*/
23
+
24
+ import java .awt .Color ;
25
+ import java .awt .Container ;
26
+ import java .awt .Dimension ;
27
+ import java .awt .Graphics ;
28
+ import java .awt .Rectangle ;
29
+ import javax .swing .JFrame ;
30
+ import javax .swing .JOptionPane ;
31
+
32
+ import java .util .Date ;
33
+
23
34
/*
24
35
* @test
25
36
* @bug 4189070
26
37
* @summary This test prints out the time it takes for a certain amount of
27
38
* copyArea calls to be completed. Because the performance measurement is
28
39
* relative, this code only provides a benchmark to run with different releases
29
40
* to compare the outcomes.
30
- * @run applet/manual=done CopyAreaSpeed.html
41
+ * @library /java/awt/regtesthelpers
42
+ * @build PassFailJFrame
43
+ * @run main/manual CopyAreaSpeed
31
44
*/
32
45
33
- import java .applet .Applet ;
34
- import java .awt .*;
35
- import java .awt .event .*;
36
- import java .util .*;
37
-
38
- public class CopyAreaSpeed extends Applet implements Runnable {
39
- int top = 0 ;
46
+ public class CopyAreaSpeed {
47
+ public static void main (String args []) throws Exception {
48
+ String instructions = """
49
+ This test prints out the time it takes for a certain amount
50
+ of copyArea calls to be completed. Because the performance
51
+ measurement is relative, this code only provides a benchmark
52
+ to run with different releases to compare the outcomes.
53
+ """ ;
54
+
55
+ PassFailJFrame .builder ()
56
+ .title ("Test Instructions" )
57
+ .instructions (instructions )
58
+ .rows (5 )
59
+ .columns (35 )
60
+ .testUI (CopyAreaSpeed ::initialize )
61
+ .build ()
62
+ .awaitAndCheck ();
63
+ }
40
64
41
- public void init () {
65
+ public static JFrame initialize () {
66
+ JFrame frame = new JFrame ("Copy Area Test" );
67
+ frame .add (new CopyAreaSpeedTest ());
68
+ frame .setSize (300 , 320 );
69
+ frame .setVisible (true );
70
+ return frame ;
42
71
}
72
+ }
73
+
74
+ class CopyAreaSpeedTest extends Container implements Runnable {
75
+ int top = 0 ;
76
+ public static String result ;
43
77
44
- public CopyAreaSpeed ()
45
- {
78
+ public CopyAreaSpeedTest () {
46
79
super ();
47
- String [] instructions =
48
- {
49
- "This test prints out the time it takes for a certain amount " ,
50
- "of copyArea calls to be completed. Because the performance " ,
51
- "measurement is relative, this code only provides a benchmark " ,
52
- "to run with different releases to compare the outcomes."
53
- };
54
- Sysout .createDialogWithInstructions ( instructions );
55
80
(new Thread (this )).start ();
56
- Button bt = new Button ("Hello" );
57
- bt .setBounds (50 , 10 , 50 , 22 );
58
- bt .setVisible (false );
59
- add (bt );
60
81
}
61
82
62
- public void update (Graphics g )
63
- {
83
+ public void update (Graphics g ) {
64
84
paint (g );
65
85
}
66
86
67
- public void paint (Graphics g )
68
- {
69
- synchronized (this ) {
87
+ public void paint (Graphics g ) {
88
+ synchronized (this ) {
70
89
Rectangle rct = g .getClipBounds ();
71
90
g .setColor (Color .white );
72
91
g .fillRect (rct .x , rct .y , rct .width , rct .height );
@@ -78,19 +97,18 @@ public void paint(Graphics g)
78
97
if (y > rct .y ) {
79
98
int z = y / 20 + top ;
80
99
g .drawString ("" + z , 10 , y );
81
- } /* endif */
82
- } // endfor
100
+ }
101
+ }
83
102
}
84
103
}
85
104
86
105
static long millsec (Date s , Date e ) {
87
106
long ts = s .getTime ();
88
107
long te = e .getTime ();
89
- return te - ts ;
108
+ return te - ts ;
90
109
}
91
110
92
- public void run ()
93
- {
111
+ public void run () {
94
112
int count = 1000 ;
95
113
int loops = count ;
96
114
Date start ;
@@ -100,7 +118,7 @@ public void run()
100
118
while (count -- > 0 ) {
101
119
Dimension dm = getSize ();
102
120
if (dm != null && dm .width != 0 && dm .height != 0 ) {
103
- synchronized (this ) {
121
+ synchronized (this ) {
104
122
top ++;
105
123
Graphics g = getGraphics ();
106
124
g .copyArea (0 , 20 , dm .width , dm .height - 20 , 0 , -20 );
@@ -111,158 +129,15 @@ public void run()
111
129
}
112
130
try {
113
131
Thread .sleep (1 );
114
- } catch (Exception ex ) {
132
+ } catch (Exception ex ) {
115
133
ex .printStackTrace ();
116
134
}
117
135
}
118
136
end = new Date ();
119
- Sysout .println ("copyArea X " +loops +" = " + millsec (start , end ) + " msec" );
120
- }
121
-
122
- public static void main (String args []) {
123
- Frame frm = new Frame ("CopyAreaSpeed" );
124
- frm .add (new CopyAreaSpeed ());
125
- frm .addWindowListener (new WindowAdapter () {
126
- public void windowClosing (WindowEvent ev ) {
127
- System .exit (0 );
128
- }
129
- });
130
- frm .setSize (500 , 500 );
131
- frm .show ();
137
+ Graphics g = getGraphics ();
138
+ g .setFont (getFont ());
139
+ g .setColor (Color .black );
140
+ result = "copyArea X " + loops + " = " + millsec (start , end ) + " msec" ;
141
+ JOptionPane .showMessageDialog (null , result );
132
142
}
133
143
}
134
- /****************************************************
135
- Standard Test Machinery
136
- DO NOT modify anything below -- it's a standard
137
- chunk of code whose purpose is to make user
138
- interaction uniform, and thereby make it simpler
139
- to read and understand someone else's test.
140
- ****************************************************/
141
-
142
- /**
143
- This is part of the standard test machinery.
144
- It creates a dialog (with the instructions), and is the interface
145
- for sending text messages to the user.
146
- To print the instructions, send an array of strings to Sysout.createDialog
147
- WithInstructions method. Put one line of instructions per array entry.
148
- To display a message for the tester to see, simply call Sysout.println
149
- with the string to be displayed.
150
- This mimics System.out.println but works within the test harness as well
151
- as standalone.
152
- */
153
- class Sysout
154
- {
155
- private static TestDialog dialog ;
156
-
157
- public static void createDialogWithInstructions ( String [] instructions )
158
- {
159
- dialog = new TestDialog ( new Frame (), "Instructions" );
160
- dialog .printInstructions ( instructions );
161
- dialog .show ();
162
- println ( "Any messages for the tester will display here." );
163
- }
164
-
165
- public static void createDialog ( )
166
- {
167
- dialog = new TestDialog ( new Frame (), "Instructions" );
168
- String [] defInstr = { "Instructions will appear here. " , "" } ;
169
- dialog .printInstructions ( defInstr );
170
- dialog .show ();
171
- println ( "Any messages for the tester will display here." );
172
- }
173
-
174
-
175
- public static void printInstructions ( String [] instructions )
176
- {
177
- dialog .printInstructions ( instructions );
178
- }
179
-
180
-
181
- public static void println ( String messageIn )
182
- {
183
- dialog .displayMessage ( messageIn );
184
- }
185
-
186
- }// Sysout class
187
-
188
- /**
189
- This is part of the standard test machinery. It provides a place for the
190
- test instructions to be displayed, and a place for interactive messages
191
- to the user to be displayed.
192
- To have the test instructions displayed, see Sysout.
193
- To have a message to the user be displayed, see Sysout.
194
- Do not call anything in this dialog directly.
195
- */
196
- class TestDialog extends Dialog
197
- {
198
-
199
- TextArea instructionsText ;
200
- TextArea messageText ;
201
- int maxStringLength = 80 ;
202
-
203
- //DO NOT call this directly, go through Sysout
204
- public TestDialog ( Frame frame , String name )
205
- {
206
- super ( frame , name );
207
- int scrollBoth = TextArea .SCROLLBARS_BOTH ;
208
- instructionsText = new TextArea ( "" , 15 , maxStringLength , scrollBoth );
209
- add ( "North" , instructionsText );
210
-
211
- messageText = new TextArea ( "" , 5 , maxStringLength , scrollBoth );
212
- add ("South" , messageText );
213
-
214
- pack ();
215
-
216
- show ();
217
- }// TestDialog()
218
-
219
- //DO NOT call this directly, go through Sysout
220
- public void printInstructions ( String [] instructions )
221
- {
222
- //Clear out any current instructions
223
- instructionsText .setText ( "" );
224
-
225
- //Go down array of instruction strings
226
-
227
- String printStr , remainingStr ;
228
- for ( int i =0 ; i < instructions .length ; i ++ )
229
- {
230
- //chop up each into pieces maxSringLength long
231
- remainingStr = instructions [ i ];
232
- while ( remainingStr .length () > 0 )
233
- {
234
- //if longer than max then chop off first max chars to print
235
- if ( remainingStr .length () >= maxStringLength )
236
- {
237
- //Try to chop on a word boundary
238
- int posOfSpace = remainingStr .
239
- lastIndexOf ( ' ' , maxStringLength - 1 );
240
-
241
- if ( posOfSpace <= 0 ) {
242
- posOfSpace = maxStringLength - 1 ;
243
- }
244
-
245
- printStr = remainingStr .substring ( 0 , posOfSpace + 1 );
246
- remainingStr = remainingStr .substring ( posOfSpace + 1 );
247
- }
248
- else //else just print
249
- {
250
- printStr = remainingStr ;
251
- remainingStr = "" ;
252
- }
253
-
254
- instructionsText .append ( printStr + "\n " );
255
-
256
- }// while
257
-
258
- }// for
259
-
260
- }//printInstructions()
261
-
262
- //DO NOT call this directly, go through Sysout
263
- public void displayMessage ( String messageIn )
264
- {
265
- messageText .append ( messageIn + "\n " );
266
- }
267
-
268
- }// TestDialog class
0 commit comments