1
1
/*
2
- * Copyright (c) 1999, 2016 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1999, 2021 , 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
33
33
* @run main RepaintTest
34
34
*/
35
35
36
- import java .awt .*;
36
+ import java .awt .BorderLayout ;
37
+ import java .awt .Button ;
38
+ import java .awt .Color ;
39
+ import java .awt .Component ;
40
+ import java .awt .Container ;
41
+ import java .awt .Frame ;
42
+ import java .awt .Panel ;
43
+ import java .awt .Point ;
44
+ import java .awt .Rectangle ;
45
+ import java .awt .TextField ;
46
+ import java .awt .Toolkit ;
37
47
import java .awt .event .*;
38
48
import javax .swing .JFrame ;
39
49
import javax .swing .JButton ;
40
50
import javax .swing .JTextField ;
41
51
import javax .swing .JPanel ;
42
- import java .io .*;
43
- import java .awt .image .*;
52
+ import java .awt .image .BufferedImage ;
53
+ import java .awt .image .PixelGrabber ;
54
+ import java .io .File ;
44
55
45
56
public class RepaintTest {
46
- private static int delay = 150 ;
57
+ private static final int delay = 150 ;
47
58
48
59
private Frame frame ;
49
60
private Container panel1 , panel2 ;
50
61
private Component button ;
51
62
private Component textField ;
52
63
private ExtendedRobot robot ;
53
- private Object buttonLock = new Object ();
64
+ private final Object buttonLock = new Object ();
54
65
private boolean passed = true ;
55
66
private boolean buttonClicked = false ;
56
- private int MAX_TOLERANCE_LEVEL = 10 ;
67
+ private final int MAX_TOLERANCE_LEVEL = 10 ;
57
68
58
69
public static void main (String [] args ) {
59
70
RepaintTest test = new RepaintTest ();
@@ -81,25 +92,6 @@ public void run() {
81
92
}
82
93
}
83
94
84
- /**
85
- * Do screen capture and save it as image
86
- */
87
- private static void captureScreenAndSave () {
88
-
89
- try {
90
- Robot robot = new Robot ();
91
- Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
92
- Rectangle rectangle = new Rectangle (0 , 0 , screenSize .width , screenSize .height );
93
- System .out .println ("About to screen capture - " + rectangle );
94
- BufferedImage image = robot .createScreenCapture (rectangle );
95
- javax .imageio .ImageIO .write (image , "jpg" , new File ("ScreenImage.jpg" ));
96
- robot .delay (3000 );
97
- } catch (Throwable t ) {
98
- System .out .println ("WARNING: Exception thrown while screen capture!" );
99
- t .printStackTrace ();
100
- }
101
- }
102
-
103
95
private void initializeGUI (boolean swingControl ) {
104
96
frame = swingControl ? new JFrame () : new Frame ();
105
97
frame .setLayout (new BorderLayout ());
@@ -115,10 +107,10 @@ private void initializeGUI(boolean swingControl) {
115
107
panel2 .add (textField );
116
108
frame .add (panel2 , BorderLayout .SOUTH );
117
109
frame .add (panel1 , BorderLayout .NORTH );
110
+ frame .setLocationRelativeTo (null );
118
111
119
112
frame .setBackground (Color .green );
120
113
frame .setVisible (true );
121
- frame .toFront ();
122
114
}
123
115
private Component createButton (boolean swingControl , String txt ) {
124
116
if (swingControl ) {
@@ -136,7 +128,7 @@ public void actionPerformed(ActionEvent e) {
136
128
}
137
129
});
138
130
return jbtn ;
139
- }else {
131
+ } else {
140
132
Button btn = new Button (txt );
141
133
btn .addActionListener (new ActionListener () {
142
134
public void actionPerformed (ActionEvent e ) {
@@ -175,10 +167,9 @@ public void run() {
175
167
176
168
robot .mouseMove (button .getLocationOnScreen ().x + button .getSize ().width / 2 ,
177
169
button .getLocationOnScreen ().y + button .getSize ().height / 2 );
170
+
171
+ robot .click ();
178
172
robot .waitForIdle (delay );
179
- robot .mousePress (InputEvent .BUTTON1_MASK );
180
- robot .waitForIdle (delay );
181
- robot .mouseRelease (InputEvent .BUTTON1_MASK );
182
173
183
174
if (! buttonClicked ) {
184
175
synchronized (buttonLock ) {
@@ -230,7 +221,6 @@ public void run() {
230
221
Toolkit .getDefaultToolkit ().getSystemEventQueue ().invokeAndWait (new Runnable () {
231
222
public void run () {
232
223
frame .setExtendedState (Frame .NORMAL );
233
- frame .toFront ();
234
224
}
235
225
});
236
226
} catch (Exception e ) {
1 commit comments
openjdk-notifier[bot] commentedon Oct 10, 2022
Review
Issues