1
1
/*
2
- * Copyright (c) 1999, 2014 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1999, 2020 , 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
29
29
run main GetSizeTest.html
30
30
*/
31
31
32
- import java .awt .*;
33
- import java .awt .event .*;
32
+ import java .awt .Choice ;
33
+ import java .awt .Frame ;
34
+ import java .awt .Panel ;
35
+ import java .awt .Point ;
36
+ import java .awt .Robot ;
37
+ import java .awt .event .InputEvent ;
38
+ import java .awt .event .MouseAdapter ;
39
+ import java .awt .event .MouseEvent ;
34
40
35
41
public class GetSizeTest {
36
42
@@ -40,16 +46,15 @@ public class GetSizeTest {
40
46
"what choices do I have?" ,
41
47
"Will I pick the same thing in the future?" ,
42
48
};
43
- static boolean passed = false ;
44
- static Robot robot = null ;
49
+ static volatile boolean passed = false ;
45
50
46
- public static void main (String args [])
47
- {
51
+ public static void main (String args []) throws Exception {
52
+ Frame f = null ;
48
53
try {
49
- robot = new Robot ();
50
- robot .setAutoDelay (50 );
54
+ Robot robot = new Robot ();
55
+ robot .setAutoDelay (150 );
51
56
52
- Frame f = new Frame ("choice test" );
57
+ f = new Frame ("choice test" );
53
58
54
59
Panel p = new Panel ();
55
60
p .setLayout (null );
@@ -70,14 +75,7 @@ public void mouseReleased(MouseEvent e) {
70
75
f .add (p );
71
76
72
77
f .setSize (300 , 300 );
73
-
74
- f .addWindowListener (new WindowAdapter () {
75
- public void windowClosing (WindowEvent we ) {
76
- System .err .println ("Test passed" );
77
- passed = true ;
78
- }
79
- });
80
-
78
+ f .setLocationRelativeTo (null );
81
79
f .setVisible (true );
82
80
83
81
c .setSize (200 , 200 );
@@ -88,14 +86,13 @@ public void windowClosing(WindowEvent we) {
88
86
Point pt = c .getLocationOnScreen ();
89
87
robot .mouseMove (pt .x + c .getWidth () - 10 , pt .y + c .getHeight () / 2 );
90
88
robot .waitForIdle ();
91
- robot .mousePress (InputEvent .BUTTON2_MASK );
92
- robot .mouseRelease (InputEvent .BUTTON2_MASK );
89
+ robot .mousePress (InputEvent .BUTTON2_DOWN_MASK );
90
+ robot .mouseRelease (InputEvent .BUTTON2_DOWN_MASK );
93
91
robot .waitForIdle ();
94
- } catch ( Throwable e ) {
95
- if (robot == null ){
96
- throw new RuntimeException ( "Test failed.Unable to initialize Robot " + e );
92
+ } finally {
93
+ if (f != null ) {
94
+ f . dispose ( );
97
95
}
98
- throw new RuntimeException ( "Test failed due to thrown exception " +e );
99
96
}
100
97
if (!passed ) {
101
98
throw new RuntimeException ( "Timeout. Choice component size is not actual size." );
0 commit comments