Path: blob/master/test/jdk/java/awt/Component/SetEnabledPerformance/SetEnabledPerformance.java
41153 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Component;24import java.awt.FlowLayout;25import java.awt.Frame;26import java.awt.Robot;2728import javax.swing.JButton;29import javax.swing.SwingUtilities;3031/**32* @test33* @key headful34* @bug 807130635* @author Sergey Bylokhov36*/37public final class SetEnabledPerformance {3839private static Frame frame;4041private static void createAndShowGUI() {42frame = new Frame();43frame.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 0));44frame.setSize(600, 600);45frame.setLocationRelativeTo(null);46for (int i = 1; i < 10001; ++i) {47frame.add(new JButton("Button " + i));48}49frame.setVisible(true);50}5152public static void main(final String[] args) throws Exception {53SwingUtilities.invokeAndWait(() -> createAndShowGUI());54final Robot robot = new Robot();55robot.waitForIdle();56robot.mouseMove(frame.getX() + 15, frame.getY() + 300);57robot.waitForIdle();58SwingUtilities.invokeAndWait(() -> {59long m = System.currentTimeMillis();60for (final Component comp : frame.getComponents()) {61comp.setEnabled(false);62}63m = System.currentTimeMillis() - m;64System.err.println("Disabled in " + m + " ms");65frame.dispose();66// we should be much faster, but leaves 1000 for the slow systems67if (m > 1000) {68throw new RuntimeException("Too slow");69}70});71}72}737475