1
1
/*
2
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2014, 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
21
21
* questions.
22
22
*/
23
23
24
- import java .awt .*;
24
+ import java .awt .Button ;
25
+ import java .awt .Canvas ;
26
+ import java .awt .Checkbox ;
27
+ import java .awt .CheckboxGroup ;
28
+ import java .awt .Choice ;
29
+ import java .awt .Color ;
30
+ import java .awt .Cursor ;
31
+ import java .awt .Dialog ;
32
+ import java .awt .Dimension ;
33
+ import java .awt .EventQueue ;
34
+ import java .awt .Label ;
35
+ import java .awt .List ;
36
+ import java .awt .Point ;
37
+ import java .awt .Scrollbar ;
38
+ import java .awt .TextArea ;
39
+ import java .awt .TextField ;
40
+ import java .awt .Toolkit ;
41
+ import java .awt .Frame ;
42
+ import java .awt .FlowLayout ;
25
43
import java .awt .image .BufferedImage ;
26
44
import java .lang .ref .PhantomReference ;
27
45
import java .lang .ref .ReferenceQueue ;
34
52
* @summary Display a dialog with a parent, the dialog contains all awt components
35
53
* added to it & each components are setted with different cursors types.
36
54
* Dispose the parent & collect GC. Garbage collection should happen
37
- * @author Dmitriy Ermashov ([email protected] )
38
55
* @library /lib/client
39
56
* @build ExtendedRobot
40
57
* @run main/othervm -Xmx20m DisposeParentGC
@@ -100,7 +117,7 @@ public void createDialog(int number) {
100
117
child .setLocation (20 , 140 * number );
101
118
102
119
Button button = new Button ("Press Me" ) ;
103
- TextArea textArea = new TextArea (5 ,5 );
120
+ TextArea textArea = new TextArea (5 , 5 );
104
121
TextField textField = new TextField (10 );
105
122
Choice choice = new Choice ();
106
123
choice .add ("One" );
@@ -115,15 +132,15 @@ public void createDialog(int number) {
115
132
list .add ("Four" );
116
133
list .add ("Five" );
117
134
Checkbox checkBox = new Checkbox ("Hai" );
118
- Scrollbar scrollBar = new Scrollbar (Scrollbar .VERTICAL ,0 , 1 , 0 , 200 );
135
+ Scrollbar scrollBar = new Scrollbar (Scrollbar .VERTICAL , 0 , 1 , 0 , 200 );
119
136
CheckboxGroup checkboxGroup = new CheckboxGroup ();
120
- Checkbox radioButton = new Checkbox ("Hello" , true , checkboxGroup );
137
+ Checkbox radioButton = new Checkbox ("Hello" , true , checkboxGroup );
121
138
Canvas canvas = new Canvas ();
122
139
Label label = new Label ("I am label!" );
123
140
Cursor customCursor = null ;
124
141
125
142
child .setLayout (new FlowLayout ());
126
- canvas .setSize (100 ,100 );
143
+ canvas .setSize (100 , 100 );
127
144
canvas .setBackground (Color .red );
128
145
129
146
button .setCursor (new Cursor (Cursor .CROSSHAIR_CURSOR ));
@@ -138,13 +155,17 @@ public void createDialog(int number) {
138
155
139
156
/* create a custom cursor */
140
157
Toolkit toolkit = Toolkit .getDefaultToolkit ();
141
- Dimension d = toolkit .getBestCursorSize (32 ,32 );
158
+ Dimension d = toolkit .getBestCursorSize (32 , 32 );
142
159
int color = toolkit .getMaximumCursorColors ();
143
160
144
- if (!d .equals (new Dimension (0 ,0 )) && color != 0 )
145
- customCursor = toolkit .createCustomCursor (new BufferedImage ( 16 , 16 , BufferedImage .TYPE_INT_RGB ), new Point (10 , 10 ), "custom cursor." );
146
- else
161
+ if (!d .equals (new Dimension (0 ,0 )) && color != 0 ) {
162
+ customCursor = toolkit .createCustomCursor (
163
+ new BufferedImage (16 , 16 , BufferedImage .TYPE_INT_RGB ),
164
+ new Point (10 , 10 ), "custom cursor." );
165
+ }
166
+ else {
147
167
System .err .println ("Platform doesn't support to create a custom cursor." );
168
+ }
148
169
149
170
textArea .setCursor (customCursor );
150
171
child .add (label );
0 commit comments