1 /*
2 * Copyright (c) 2016, 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 8154434
27 @summary Open the request focus methods of the java.awt.Component which accept
28 FocusEvent.Cause
29 @run main RequestFocusByCauseTest
30 */
31
32 import java.awt.*;
33 import java.awt.event.FocusEvent;
34 import java.awt.event.FocusListener;
35
36 public class RequestFocusByCauseTest {
37 static boolean success;
38
39 public static void main(String[] args) throws Exception {
40 testRequestFocusCause();
41 testRequestFocusTemporaryCause();
42 testRequestFocusInWindowCause();
43 System.out.println("ok");
44 }
45
46 private static void testRequestFocusCause() throws AWTException {
47 Frame frame = new Frame();
48 Component c = new Button();
49 frame.add(new Button());
50 frame.add(c);
132 });
133 Robot robot = new Robot();
134
135 try {
136 frame.setVisible(true);
137 robot.waitForIdle();
138 robot.delay(200);
139 success = false;
140
141 c.requestFocusInWindow(FocusEvent.Cause.UNEXPECTED);
142 robot.waitForIdle();
143 robot.delay(200);
144 if (!success) {
145 throw new RuntimeException("request in window failed");
146 }
147 } finally {
148 frame.dispose();
149 }
150 }
151 }
|
1 /*
2 * Copyright (c) 2016, 2017, 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 * @key headful
27 * @bug 8154434
28 * @summary Open the request focus methods of the java.awt.Component which accept
29 * FocusEvent.Cause
30 * @run main RequestFocusByCauseTest
31 */
32
33 import java.awt.*;
34 import java.awt.event.FocusEvent;
35 import java.awt.event.FocusListener;
36
37 public class RequestFocusByCauseTest {
38 static boolean success;
39
40 public static void main(String[] args) throws Exception {
41 testRequestFocusCause();
42 testRequestFocusTemporaryCause();
43 testRequestFocusInWindowCause();
44 System.out.println("ok");
45 }
46
47 private static void testRequestFocusCause() throws AWTException {
48 Frame frame = new Frame();
49 Component c = new Button();
50 frame.add(new Button());
51 frame.add(c);
133 });
134 Robot robot = new Robot();
135
136 try {
137 frame.setVisible(true);
138 robot.waitForIdle();
139 robot.delay(200);
140 success = false;
141
142 c.requestFocusInWindow(FocusEvent.Cause.UNEXPECTED);
143 robot.waitForIdle();
144 robot.delay(200);
145 if (!success) {
146 throw new RuntimeException("request in window failed");
147 }
148 } finally {
149 frame.dispose();
150 }
151 }
152 }
153
|