java.awt.Robot#waitForIdle ( )源码实例Demo

下面列出了java.awt.Robot#waitForIdle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u   文件: MenuItemIconTest.java
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
源代码2 项目: jdk8u-jdk   文件: MenuItemIconTest.java
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
源代码3 项目: openjdk-jdk9   文件: LightweightEventTest.java
public static void main(String[] args) throws Throwable {

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                constructTestUI();
            }
        });

        try {
            testRobot = new Robot();
        } catch (AWTException ex) {
            throw new RuntimeException("Could not initiate a drag operation");
        }

        testRobot.waitForIdle();

        // Method performing auto test operation
        boolean result = test();

        disposeTestUI();

        if (result == false) {
            throw new RuntimeException("Test FAILED!");
        }
    }
 
源代码4 项目: dragonwell8_jdk   文件: MenuItemIconTest.java
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
源代码5 项目: TencentKona-8   文件: MenuItemIconTest.java
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
源代码6 项目: openjdk-jdk9   文件: bug7055065.java
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowUI();
        }
    });

    robot.waitForIdle();
    clickCell(robot, 1, 1);
    Util.hitKeys(robot, KeyEvent.VK_BACK_SPACE, KeyEvent.VK_BACK_SPACE,
            KeyEvent.VK_BACK_SPACE);

    robot.waitForIdle();
    clickColumnHeader(robot, 1);

    robot.waitForIdle();
    clickColumnHeader(robot, 1);
}
 
源代码7 项目: openjdk-jdk9   文件: MultiResolutionSplashTest.java
static void testFocus() throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if (!textField.getText().equals("ab")) {
            throw new RuntimeException("Focus is lost!");
        }
    }
 
源代码8 项目: hottub   文件: Test8013370.java
public static void main(String[] args) throws Exception {
    Test8013370 task = new Test8013370();
    invokeAndWait(task);

    Robot robot = new Robot();
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.waitForIdle();

    invokeAndWait(task);
    task.validate();
}
 
源代码9 项目: openjdk-jdk9   文件: bug4458079.java
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.waitForIdle();
    // move mouse outside menu to prevent auto selection
    robot.mouseMove(100,100);

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            new bug4458079().createAndShowGUI();
        }
    });

    robot.setAutoDelay(50);

    Util.hitMnemonics(robot, KeyEvent.VK_M);

    robot.waitForIdle();
    Thread.sleep(1000);

    Util.hitKeys(robot, KeyEvent.VK_DOWN);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);

    robot.waitForIdle();
    Thread.sleep(1000);

    if (!itemASelected) {
        throw new RuntimeException("Test failed: arrow key traversal in JMenu broken!");
    }
}
 
源代码10 项目: openjdk-jdk9   文件: DockIconRepaint.java
public static void main(final String[] args) throws Exception {
    robot = new Robot();
    EventQueue.invokeAndWait(DockIconRepaint::createUI);
    try {
        robot.waitForIdle();
        color = Color.BLUE;
        test();
        color = Color.RED;
        test();
        color = Color.GREEN;
        test();
    } finally {
        frame.dispose();
    }
}
 
public static void main(String[] args) throws Exception {
    robot = new Robot();
    robot.waitForIdle();
    UIManager.LookAndFeelInfo[] lookAndFeelArray
            = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
        executeCase(lookAndFeelItem.getClassName(),
                lookAndFeelItem.getName());

    }
    if (!"".equals(errorString)) {
        System.err.println(errorString);
    }
}
 
源代码12 项目: openjdk-jdk9   文件: OptionPaneTest.java
public static void main(final String[] args) throws Exception {
    robot = new Robot();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            try {
                JOptionPane optionPane = new JOptionPane("JOptionPane",
                        JOptionPane.INFORMATION_MESSAGE,
                        JOptionPane.DEFAULT_OPTION,
                        null,
                        new String[]{"3", "2", "1"},
                        null);
                dialog = optionPane.createDialog("JOptionPane");
                int width = 0;
                Component[] comps = optionPane.getComponents();
                for (Component comp : comps) {
                    if (comp instanceof JPanel) {
                        Component[] child = ((JPanel) comp).getComponents();
                        for (Component c : child) {
                            if (c instanceof JButton) {
                                width += c.getWidth();
                            }
                        }
                    }
                }
                Insets in = optionPane.getInsets();
                width += in.left + in.right;
                if (width > optionPane.getWidth()) {
                    testFailed = true;
                }
            } finally {
                dialog.dispose();
            }
        }
    });
    robot.waitForIdle();
    if (testFailed) {
        throw new RuntimeException("Test Failed");
    }
}
 
源代码13 项目: openjdk-jdk9   文件: bug8017284.java
public static void main(String[] args) throws Exception {

        Robot robot = new Robot();
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            frame.setSize(500, 500);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            tabbedPane = new JTabbedPane();

            for (int i = 0; i < TAB_COUNT; i++) {
                tabbedPane.add("Header " + i, new JLabel("Content: " + i));
            }

            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
            frame.setVisible(true);
        });

        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            for (int j = 0; j < ITERATIONS; j++) {
                for (int i = 0; i < TAB_COUNT; i++) {
                    tabbedPane.setTitleAt(i, getHtmlText(j * TAB_COUNT + i));
                }
            }
        });
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> frame.dispose());
    }
 
源代码14 项目: jdk8u-jdk   文件: Test8013370.java
public static void main(String[] args) throws Exception {
    Test8013370 task = new Test8013370();
    invokeAndWait(task);

    Robot robot = new Robot();
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.waitForIdle();

    invokeAndWait(task);
    task.validate();
}
 
源代码15 项目: openjdk-jdk9   文件: MultiScreenRobotPosition.java
public static void main(String[] args) throws Exception {
    GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment()
                                              .getScreenDevices();
    for (final GraphicsDevice gd : sds) {
        fail = true;
        Robot robot = new Robot(gd);
        robot.setAutoDelay(100);
        robot.setAutoWaitForIdle(true);

        Frame frame = new Frame(gd.getDefaultConfiguration());
        frame.setUndecorated(true);
        frame.setSize(400, 400);
        frame.setVisible(true);
        robot.waitForIdle();

        frame.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("e = " + e);
                fail = false;
            }
        });

        Rectangle bounds = frame.getBounds();
        robot.mouseMove(bounds.x + bounds.width / 2,
                        bounds.y + bounds.height / 2);
        robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
        frame.dispose();
        if (fail) {
            System.err.println("Frame bounds = " + bounds);
            throw new RuntimeException("Click in the wrong location");
        }
    }
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: ConsumedKeyTest.java
private static void test(final int key) throws Exception {
    passed = false;
    try {
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            JComboBox<String> combo = new JComboBox<>(new String[]{"one", "two", "three"});
            JPanel panel = new JPanel();
            panel.add(combo);
            combo.requestFocusInWindow();
            frame.setBounds(100, 150, 300, 100);
            addAction(panel, key);
            frame.add(panel);
            frame.setVisible(true);
        });

        Robot robot = new Robot();
        robot.waitForIdle();
        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
        robot.keyPress(key);
        robot.waitForIdle();
        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
        robot.keyRelease(key);
        robot.waitForIdle();
        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
        if (!passed) {
            throw new RuntimeException("FAILED: " + KeyEvent.getKeyText(key) + " was consumed by combo box");
        }
    } finally {
        if (frame != null) {
            frame.dispose();
        }
    }

}
 
源代码17 项目: openjdk-jdk9   文件: bug8033699.java
private static void hitKey(Robot robot, int keycode) {
    robot.keyPress(keycode);
    robot.keyRelease(keycode);
    robot.waitForIdle();
}
 
public static void performTasks(Robot robotForKeyInput) throws Exception {
    lblTestStatus.setText("Running Tests..");
    robotForKeyInput.setAutoDelay(500);

    ArrayList<Integer> keyCodesToUse = new ArrayList<Integer>();

    keyCodesToUse.add(KeyEvent.VK_A);
    keyCodesToUse.add(KeyEvent.VK_B);
    keyCodesToUse.add(KeyEvent.VK_E);
    keyCodesToUse.add(KeyEvent.VK_SPACE);
    keyCodesToUse.add(KeyEvent.VK_SPACE);
    keyCodesToUse.add(KeyEvent.VK_ENTER);
    keyCodesToUse.add(KeyEvent.VK_S);
    keyCodesToUse.add(KeyEvent.VK_I);
    keyCodesToUse.add(KeyEvent.VK_N);
    keyCodesToUse.add(KeyEvent.VK_Z);
    keyCodesToUse.add(KeyEvent.VK_O);
    keyCodesToUse.add(KeyEvent.VK_U);
    keyCodesToUse.add(KeyEvent.VK_SPACE);
    keyCodesToUse.add(KeyEvent.VK_ENTER);

    textFieldMain.requestFocusInWindow();

    robotForKeyInput.waitForIdle();

    enterInput(robotForKeyInput, keyCodesToUse);

    SwingUtilities.invokeAndWait(() -> {
        readingPass1 = textFieldReading.getText();
    });

    if (setTaskStatus(readingPass1, 1)) {
        keyCodesToUse.remove((Integer) KeyEvent.VK_ENTER);

        enterInput(robotForKeyInput, keyCodesToUse);

        SwingUtilities.invokeAndWait(() -> {
            readingPass2 = textFieldReading.getText();
        });

        if (setTaskStatus(readingPass2, 2)) {
            if (readingPass1.equals(readingPass2)) {
                testPassed = true;
                testResult = "Test Passed : Same reading attribute "
                        + "obtained from both passes ";
                lblTestStatus.setText(testResult);
            } else {
                testResult = "Test Failed : Reading attribute from Pass 1 <"
                        + readingPass1 + "> != Reading attribute "
                        + "from Pass 2 <" + readingPass2 + ">";
            }
        }
    }
}
 
源代码19 项目: openjdk-jdk9   文件: bug4973721.java
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel("javax.swing.plaf.synth.SynthLookAndFeel");

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            final JFrame frame = new JFrame();
            spinner = new JSpinner();
            frame.getContentPane().add(spinner);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            frame.pack();
            frame.setVisible(true);
            spinner.addChangeListener((ChangeListener)listener);
            spinner.addFocusListener((FocusListener)listener);
            spinner.requestFocus();

        }
    });

    synchronized(listener) {
        if (!bFocusGained) {
            System.out.println("waiting focusGained...");
            try { listener.wait(5000); } catch (InterruptedException e) {}
        }
    }

    boolean hasFocus = Util.invokeOnEDT(new java.util.concurrent.Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return spinner.hasFocus();
        }
    });

    if (!bFocusGained && !hasFocus) {
        throw new RuntimeException("Couldn't request focus for spinner");
    }
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    Util.hitKeys(robot, KeyEvent.VK_UP);
    robot.waitForIdle();
    Thread.sleep(1000);

    if (!bStateChanged) {
        throw new RuntimeException("Up arrow key button doesn't work for a spinner in Synth L&F");
    }

    bStateChanged = false;

    Util.hitKeys(robot, KeyEvent.VK_DOWN);
    robot.waitForIdle();
    Thread.sleep(1000);

    if (!bStateChanged) {
        throw new RuntimeException("Down arrow key button doesn't work for a spinner in Synth L&F");
    }
}
 
源代码20 项目: dragonwell8_jdk   文件: ImageViewTest.java
public static void main(String[] args) throws Exception {

        final String ABSOLUTE_FILE_PATH = ImageViewTest.class.getResource("circle.png").getPath();

        System.out.println(ABSOLUTE_FILE_PATH);

        Robot r = new Robot();

        final JEditorPane[] editorPanes = new JEditorPane[11];

        SwingUtilities.invokeAndWait(() -> {
            editorPanes[0] = new JEditorPane("text/html",
                    "<img height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[1] = new JEditorPane("text/html",
                    "<img width=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[2] = new JEditorPane("text/html",
                    "<img width=\"200\" height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[3] = new JEditorPane("text/html",
                    "<img src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[4] = new JEditorPane("text/html",
                    "<img width=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[5] = new JEditorPane("text/html",
                    "<img height=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[6] = new JEditorPane("text/html",
                    "<img width=\"100\" height=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[7] = new JEditorPane("text/html",
                    "<img width=\"50\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[8] = new JEditorPane("text/html",
                    "<img height=\"50\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[9] = new JEditorPane("text/html",
                    "<img width=\"300\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[10] = new JEditorPane("text/html",
                    "<img height=\"300\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

        });

        r.waitForIdle();

        System.out.println("Test with only height set to 200");
        test(r, editorPanes[0], 200, 200);

        System.out.println("Test with only width set to 200");
        test(r, editorPanes[1], 200, 200);

        System.out.println("Test with both of them set");
        test(r, editorPanes[2], 200, 200);

        System.out.println("Test with none of them set to 200");
        test(r, editorPanes[3], 200, 200);

        System.out.println("Test with only width set to 100");
        test(r, editorPanes[4], 100, 100);

        System.out.println("Test with only height set to 100");
        test(r, editorPanes[5], 100, 100);

        System.out.println("Test with both width and height set to 100");
        test(r, editorPanes[6], 100, 100);

        System.out.println("Test with only width set to 50");
        test(r, editorPanes[7], 50, 50);

        System.out.println("Test with only height set to 50");
        test(r, editorPanes[8], 50, 50);

        System.out.println("Test with only width set to 300");
        test(r, editorPanes[9], 300, 300);

        System.out.println("Test with only height set to 300");
        test(r, editorPanes[10], 300, 300);

        System.out.println("Test Passed.");
    }