1 /* |
1 /* |
2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 test |
25 @test |
26 @bug 4041703 4096228 4025223 4260929 |
26 @key headful |
|
27 @bug 4041703 4096228 4025223 4260929 |
27 @summary Ensures that appletviewer sets a reasonable default focus for an Applet on start |
28 @summary Ensures that appletviewer sets a reasonable default focus for an Applet on start |
28 @author das area=appletviewer |
29 @library ../../regtesthelpers |
29 @run applet AppletInitialFocusTest.html |
30 @build Util |
|
31 @run main AppletInitialFocusTest |
30 */ |
32 */ |
31 |
33 |
32 import java.applet.Applet; |
|
33 import java.awt.Button; |
34 import java.awt.Button; |
34 import java.awt.Component; |
35 import java.awt.FlowLayout; |
|
36 import java.awt.Frame; |
35 import java.awt.Robot; |
37 import java.awt.Robot; |
36 import java.awt.Window; |
|
37 import test.java.awt.regtesthelpers.Util; |
38 import test.java.awt.regtesthelpers.Util; |
38 |
39 |
39 public class AppletInitialFocusTest extends Applet { |
40 public class AppletInitialFocusTest extends Frame { |
|
41 |
40 Robot robot = Util.createRobot(); |
42 Robot robot = Util.createRobot(); |
41 Button button = new Button("Button"); |
43 Button button = new Button("Button"); |
42 |
44 |
43 public void init() { |
45 public static void main(final String[] args) throws Exception { |
44 add(button); |
46 AppletInitialFocusTest app = new AppletInitialFocusTest(); |
|
47 app.init(); |
|
48 app.start(); |
45 } |
49 } |
46 |
50 |
47 public void start() { |
51 public void init() { |
48 new Thread(new Runnable() { |
52 setSize(200, 200); |
|
53 setLocationRelativeTo(null); |
|
54 setLayout(new FlowLayout()); |
|
55 add(button); |
|
56 setVisible(true); |
|
57 } |
|
58 |
|
59 public void start() throws Exception { |
|
60 Thread thread = new Thread(new Runnable() { |
49 public void run() { |
61 public void run() { |
50 Util.waitTillShown(button); |
62 Util.waitTillShown(button); |
51 robot.delay(1000); // delay the thread to let EDT to start dispatching focus events |
63 robot.delay(1000); // delay the thread to let EDT to start dispatching focus events |
52 Util.waitForIdle(robot); |
64 Util.waitForIdle(robot); |
53 if (!button.hasFocus()) { |
65 if (!button.hasFocus()) { |
54 throw new RuntimeException("Appletviewer doesn't set default focus correctly."); |
66 throw new RuntimeException("Appletviewer doesn't set default focus correctly."); |
55 } |
67 } |
56 } |
68 } |
57 }).start(); |
69 }); |
|
70 thread.start(); |
|
71 thread.join(); |
58 } |
72 } |
59 } |
73 } |