Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Component/SetEnabledPerformance/SetEnabledPerformance.java
41153 views
1
/*
2
* Copyright (c) 2015, 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.Component;
25
import java.awt.FlowLayout;
26
import java.awt.Frame;
27
import java.awt.Robot;
28
29
import javax.swing.JButton;
30
import javax.swing.SwingUtilities;
31
32
/**
33
* @test
34
* @key headful
35
* @bug 8071306
36
* @author Sergey Bylokhov
37
*/
38
public final class SetEnabledPerformance {
39
40
private static Frame frame;
41
42
private static void createAndShowGUI() {
43
frame = new Frame();
44
frame.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 0));
45
frame.setSize(600, 600);
46
frame.setLocationRelativeTo(null);
47
for (int i = 1; i < 10001; ++i) {
48
frame.add(new JButton("Button " + i));
49
}
50
frame.setVisible(true);
51
}
52
53
public static void main(final String[] args) throws Exception {
54
SwingUtilities.invokeAndWait(() -> createAndShowGUI());
55
final Robot robot = new Robot();
56
robot.waitForIdle();
57
robot.mouseMove(frame.getX() + 15, frame.getY() + 300);
58
robot.waitForIdle();
59
SwingUtilities.invokeAndWait(() -> {
60
long m = System.currentTimeMillis();
61
for (final Component comp : frame.getComponents()) {
62
comp.setEnabled(false);
63
}
64
m = System.currentTimeMillis() - m;
65
System.err.println("Disabled in " + m + " ms");
66
frame.dispose();
67
// we should be much faster, but leaves 1000 for the slow systems
68
if (m > 1000) {
69
throw new RuntimeException("Too slow");
70
}
71
});
72
}
73
}
74
75