1 /* |
1 /* |
2 * Copyright (c) 2008, 2013, 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. |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 import java.applet.Applet; |
|
25 import java.awt.*; |
24 import java.awt.*; |
26 import java.awt.event.*; |
25 import java.awt.event.*; |
27 |
26 |
28 public class AppletInitialFocusTest1 extends Applet implements FocusListener { |
27 /* |
|
28 @test |
|
29 @key headful |
|
30 @bug 4411534 4517274 |
|
31 @summary ensures that user's requestFocus() during applet initialization |
|
32 is not ignored |
|
33 @library ../../regtesthelpers |
|
34 @build Util |
|
35 @run main AppletInitialFocusTest1 |
|
36 */ |
|
37 public class AppletInitialFocusTest1 extends Frame implements FocusListener { |
29 |
38 |
30 Button button1 = new Button("Button1"); |
39 Button button1 = new Button("Button1"); |
31 Button button2 = new Button("Button2"); |
40 Button button2 = new Button("Button2"); |
32 |
41 |
33 Object lock = new Object(); |
42 Object lock = new Object(); |
34 |
43 |
|
44 public static void main(final String[] args) throws Exception { |
|
45 AppletInitialFocusTest1 app = new AppletInitialFocusTest1(); |
|
46 app.init(); |
|
47 Thread.sleep(10000); |
|
48 } |
|
49 |
35 public void init() { |
50 public void init() { |
|
51 setSize(200, 200); |
|
52 setLocationRelativeTo(null); |
|
53 setLayout(new FlowLayout()); |
36 |
54 |
37 Component parent = this; |
55 Component parent = this; |
38 while (parent != null && !(parent instanceof Window)) { |
56 while (parent != null && !(parent instanceof Window)) { |
39 parent = parent.getParent(); |
57 parent = parent.getParent(); |
40 } |
58 } |
50 } |
68 } |
51 button1.addFocusListener(this); |
69 button1.addFocusListener(this); |
52 button2.addFocusListener(this); |
70 button2.addFocusListener(this); |
53 add(button1); |
71 add(button1); |
54 add(button2); |
72 add(button2); |
|
73 setVisible(true); |
55 button2.requestFocus(); |
74 button2.requestFocus(); |
56 } |
75 } |
57 |
76 |
58 public void focusGained(FocusEvent e) { |
77 public void focusGained(FocusEvent e) { |
59 if (e.getSource() == button1) { |
78 if (e.getSource() == button1) { |
60 synchronized (lock) { |
79 synchronized (lock) { |
61 System.err.println("failed: focus on the wrong button"); |
80 throw new RuntimeException("failed: focus on the wrong button"); |
62 System.exit(2); |
|
63 } |
81 } |
64 } |
82 } |
65 } |
83 } |
66 |
84 |
67 public void focusLost(FocusEvent e) { |
85 public void focusLost(FocusEvent e) { |
68 } |
86 } |
69 |
|
70 public void start() { |
|
71 Thread thread = new Thread(new Runnable() { |
|
72 public void run() { |
|
73 try { |
|
74 Thread.sleep(10000); |
|
75 synchronized (lock) { |
|
76 System.err.println("passed"); |
|
77 System.exit(0); |
|
78 } |
|
79 } catch(InterruptedException e) { |
|
80 } |
|
81 } |
|
82 }); |
|
83 thread.start(); |
|
84 } |
|
85 } |
87 } |