Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Focus/AppletInitialFocusTest/AppletInitialFocusTest1.java
41152 views
1
/*
2
* Copyright (c) 2008, 2020, 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
import java.awt.Button;
25
import java.awt.FlowLayout;
26
import java.awt.Frame;
27
import java.awt.event.FocusEvent;
28
import java.awt.event.FocusListener;
29
30
/**
31
* @test
32
* @key headful
33
* @bug 4411534 4517274
34
* @summary ensures that user's requestFocus() during applet initialization
35
* is not ignored
36
*/
37
public class AppletInitialFocusTest1 extends Frame implements FocusListener {
38
39
Button button1 = new Button("Button1");
40
Button button2 = new Button("Button2");
41
private static volatile Object focused;
42
43
public static void main(final String[] args) throws Exception {
44
AppletInitialFocusTest1 app = new AppletInitialFocusTest1();
45
try {
46
app.setSize(200, 200);
47
app.setLocationRelativeTo(null);
48
app.setLayout(new FlowLayout());
49
50
app.button1.addFocusListener(app);
51
app.button2.addFocusListener(app);
52
app.add(app.button1);
53
app.add(app.button2);
54
app.setVisible(true);
55
app.button2.requestFocus();
56
// wait for the very very last focus event
57
Thread.sleep(10000);
58
if (app.button2 != focused) {
59
throw new RuntimeException("Wrong focus owner: " + focused);
60
}
61
} finally {
62
app.dispose();
63
}
64
}
65
66
public void focusGained(FocusEvent e) {
67
focused = e.getSource();
68
System.out.println("focused = " + focused);
69
}
70
71
public void focusLost(FocusEvent e) {
72
}
73
}
74
75