Java Code Examples for java.awt.Robot#setAutoDelay()

The following examples show how to use java.awt.Robot#setAutoDelay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: bug4524490.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser();
            fileChooser.showOpenDialog(null);
        }
    });

    toolkit.realSync();

    if (OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())) {
        Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_L);
    } else {
        Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_L);
    }
    checkFocus();
}
 
Example 2
Source File: RemovedComponentMouseListener.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        new RemovedComponentMouseListener();
    });

    Robot r = Util.createRobot();
    r.setAutoDelay(100);
    r.waitForIdle();
    Util.pointOnComp(button, r);

    r.waitForIdle();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    if (!mouseReleasedReceived) {
        throw new RuntimeException("mouseReleased event was not received");
    }
}
 
Example 3
Source File: BackgroundIsNotUpdated.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    sleep();
    window.setBackground(Color.GREEN);
    sleep();
    final Robot robot = new Robot();
    robot.setAutoDelay(200);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
Example 4
Source File: SlowPanelIteration.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    Robot r = new Robot();
    // accessibility tool will need time to react to our clicks
    r.setAutoDelay(200);
    try {
        EventQueue.invokeAndWait(SlowPanelIteration::showUI);
        for (int i = 0; i < 10; ++i) {
            go = new CountDownLatch(1);
            r.mouseMove(center.x, center.y);
            r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
            if (!go.await(10, TimeUnit.SECONDS)) {
                throw new RuntimeException("Too slow operation");
            }
        }
    } finally {
        EventQueue.invokeAndWait(SlowPanelIteration::dispose);
    }
}
 
Example 5
Source File: Test6505027.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void press() throws AWTException {
    Point point = this.table.getCellRect(1, 1, false).getLocation();
    SwingUtilities.convertPointToScreen(point, this.table);

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.mouseMove(point.x + 1, point.y + 1);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example 6
Source File: Test6505027.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void press() throws AWTException {
    Point point = this.table.getCellRect(1, 1, false).getLocation();
    SwingUtilities.convertPointToScreen(point, this.table);

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.mouseMove(point.x + 1, point.y + 1);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example 7
Source File: bug8057893.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

    EventQueue.invokeAndWait(() -> {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"});
        comboBox.setEditable(true);
        comboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if ("comboBoxEdited".equals(e.getActionCommand())) {
                    isComboBoxEdited = true;
                }
            }
        });
        frame.add(comboBox);
        frame.pack();
        frame.setVisible(true);
        comboBox.requestFocusInWindow();
    });

    toolkit.realSync();

    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    toolkit.realSync();

    if(!isComboBoxEdited){
        throw new RuntimeException("ComboBoxEdited event is not fired!");
    }
}
 
Example 8
Source File: bug4743225.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(20);
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                new bug4743225().setVisible(true);
            }
        });
        toolkit.realSync();

        // calling this method from main thread is ok
        Point point = cb.getLocationOnScreen();
        robot.mouseMove(point.x + 10, point.y + 10);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                if(getPopup().getList().getLastVisibleIndex() == 3) {
                    flag = true;
                }
            }
        });

        if (!flag) {
            throw new RuntimeException("The ComboBox popup wasn't correctly updated");
        }
    }
 
Example 9
Source File: bug4743225.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(20);
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                new bug4743225().setVisible(true);
            }
        });
        toolkit.realSync();

        // calling this method from main thread is ok
        Point point = cb.getLocationOnScreen();
        robot.mouseMove(point.x + 10, point.y + 10);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                if(getPopup().getList().getLastVisibleIndex() == 3) {
                    flag = true;
                }
            }
        });

        if (!flag) {
            throw new RuntimeException("The ComboBox popup wasn't correctly updated");
        }
    }
 
Example 10
Source File: NSTexturedJFrame.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void showFrame() throws Exception {
    final Robot robot = new Robot();
    robot.setAutoDelay(50);
    createUI();
    images[step] = robot.createScreenCapture(bounds);
    SwingUtilities.invokeAndWait(frame::dispose);
    sleep();
}
 
Example 11
Source File: AltTabCrashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    try {
        robot = new Robot();
        robot.setAutoDelay(200);
    } catch (AWTException e) {
        throw new RuntimeException("Can't create robot");
    }
    boolean out = true;
    while (altTabs-- > 0 && !timeToQuit) {
        System.err.println("Alt+tabber Iteration: "+altTabs);
        try { Thread.sleep(2500); } catch (InterruptedException ex) {}

        if (out) {
            System.err.println("Issuing alt+tab");
            pressAltTab();
        } else {
            System.err.println("Issuing shift ");
            pressShiftAltTab();
        }
        out = !out;
    }
    System.err.println("Alt+tabber finished.");
    synchronized (lock) {
        timeToQuit = true;
        lock.notify();
    }
}
 
Example 12
Source File: SelectionInvisibleTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);
        TextField textField = new TextField(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        toolkit.realSync();

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

        Point point = textField.getLocationOnScreen();
        int x = point.x + textField.getWidth() / 2;
        int y = point.y + textField.getHeight() / 2;
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        robot.mousePress(InputEvent.BUTTON1_MASK);
        int N = 10;
        int dx = textField.getWidth() / N;
        for (int i = 0; i < N; i++) {
            x += dx;
            robot.mouseMove(x, y);
        }
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
 
Example 13
Source File: PaintNativeOnUpdate.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    final Frame frame = new Frame();
    final Component label = new PaintNativeOnUpdate();
    frame.setBackground(Color.RED);
    frame.add(label);
    frame.setSize(300, 300);
    frame.setUndecorated(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    label.repaint();// first paint
    sleep();
    label.repaint();// incremental paint
    sleep();

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Point point = label.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
                                      point.y + label.getHeight() / 2);
    if (!color.equals(Color.GREEN)) {
        System.err.println("Expected color = " + Color.GREEN);
        System.err.println("Actual color = " + color);
        throw new RuntimeException();
    }
    frame.dispose();
}
 
Example 14
Source File: bug4458079.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            new bug4458079().createAndShowGUI();
        }
    });
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();

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

    Util.hitMnemonics(robot, KeyEvent.VK_M);

    toolkit.realSync();
    Thread.sleep(1000);

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

    toolkit.realSync();
    Thread.sleep(1000);

    if (!itemASelected) {
        throw new RuntimeException("Test failed: arrow key traversal in JMenu broken!");
    }
}
 
Example 15
Source File: MissingCharsKorean.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void performTasks(Robot robotForKeyInput) {
    int taskCount = 0;

    lblTestStatus.setText("Running Tests..");
    robotForKeyInput.setAutoDelay(500);

    while (setKeyInput(taskCount)) {
        textFieldMain.setText("");
        textFieldMain.requestFocusInWindow();
        enterInput(robotForKeyInput, inKeyCodes);
        taskCount++;

        try {
            SwingUtilities.invokeAndWait(() -> {
                validateInput();
            });
        } catch (Exception e) {
            System.err.print("validateInput Failed : " + e.getMessage());
            testPassed = false;
            break;
        }

        if (!testPassed) {
            break;
        }
        setTaskStatus(false, taskCount);
    }
    setTaskStatus(true, taskCount);
}
 
Example 16
Source File: MenuBarSetFont.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) throws Exception {

        if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.MACOSX) {
            System.err.println("This test is not for OS X. Menu.setFont() is not supported on OS X.");
            return;
        }

        //Components initialization.
        frame.setMenuBar(mb);
        mb.setFont(new Font("Helvetica", Font.ITALIC, 5));

        final Button button = new Button("Click Me");
        button.addActionListener(new Listener());
        frame.setLayout(new CardLayout());
        frame.add(button, "First");
        frame.setSize(400, 400);
        frame.setVisible(true);
        sleep();

        final int fInsets = frame.getInsets().top;  //Frame insets without menu.
        addMenu();
        final int fMenuInsets = frame.getInsets().top; //Frame insets with menu.
        final int menuBarHeight = fMenuInsets - fInsets;
        // There is no way to change menubar height on windows. But on windows
        // we can try to split menubar in 2 rows.
        for (int i = 0; i < 100 && fMenuInsets == frame.getInsets().top; ++i) {
            // Fill whole menubar.
            addMenu();
        }

        mb.remove(0);
        frame.validate();
        sleep();

        // Test execution.
        // On XToolkit, menubar font should be changed to 60.
        // On WToolkit, menubar font should be changed to default and menubar
        // should be splitted in 2 rows.
        mb.setFont(new Font("Helvetica", Font.ITALIC, 60));
        sleep();

        final Robot r = new Robot();
        r.setAutoDelay(200);
        final Point pt = frame.getLocation();
        r.mouseMove(pt.x + frame.getWidth() / 2,
                    pt.y + fMenuInsets + menuBarHeight / 2);
        r.mousePress(InputEvent.BUTTON1_MASK);
        r.mouseRelease(InputEvent.BUTTON1_MASK);

        sleep();
        frame.dispose();

        if (clicked) {
            fail("Font was not changed");
        }
    }
 
Example 17
Source File: bug8069348.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (!isSupported()) {
            return;
        }

        try {

            SwingUtilities.invokeAndWait(bug8069348::createAndShowGUI);

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

            Rectangle screenBounds = getInternalFrameScreenBounds();

            int x = screenBounds.x + screenBounds.width / 2;
            int y = screenBounds.y + 10;
            int dx = screenBounds.width / 2;
            int dy = screenBounds.height / 2;

            robot.mouseMove(x, y);
            robot.waitForIdle();

            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseMove(x + dx, y + dy);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            robot.waitForIdle();

            int cx = screenBounds.x + screenBounds.width + dx / 2;
            int cy = screenBounds.y + screenBounds.height + dy / 2;

            robot.mouseMove(cx, cy);
            if (!FRAME_COLOR.equals(robot.getPixelColor(cx, cy))) {
                throw new RuntimeException("Internal frame is not correctly dragged!");
            }
        } finally {
            if (frame != null) {
                frame.dispose();
            }
        }
    }
 
Example 18
Source File: WindowOwnedByEmbeddedFrameTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    try {
        Robot robot = Util.createRobot();
        robot.setAutoDelay(50);

        embeddedFrame = createEmbeddedFrame();

        textField = new TextField("");

        window = new Window(embeddedFrame);
        window.setSize(200, 200);
        window.setLocationRelativeTo(null);
        window.add(textField);
        window.setVisible(true);

        Util.waitForIdle(robot);

        Util.clickOnComp(textField, robot);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_T);
        robot.keyRelease(KeyEvent.VK_T);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_E);
        robot.keyRelease(KeyEvent.VK_E);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_S);
        robot.keyRelease(KeyEvent.VK_S);
        Util.waitForIdle(robot);

        robot.keyPress(KeyEvent.VK_T);
        robot.keyRelease(KeyEvent.VK_T);
        Util.waitForIdle(robot);

        if ("".equals(textField.getText())) {
            throw new RuntimeException("Keyboard input in text field isn't possible");
        }
    } finally {
        if (embeddedFrame != null) {
            embeddedFrame.dispose();
        }
        if (window != null) {
            window.dispose();
        }
    }
}
 
Example 19
Source File: ViewportOverlapping.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected boolean performTest() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                // prepare test data
                frameClicked = 0;

                b.requestFocus();

                scrollPane.getHorizontalScrollBar().setUnitIncrement(40);
                scrollPane.getVerticalScrollBar().setUnitIncrement(40);

                hLoc = scrollPane.getHorizontalScrollBar().getLocationOnScreen();
                hLoc.translate(scrollPane.getHorizontalScrollBar().getWidth() - 3, 3);
                vLoc = scrollPane.getVerticalScrollBar().getLocationOnScreen();
                vLoc.translate(3, scrollPane.getVerticalScrollBar().getHeight() - 3);

                testLoc = p.getLocationOnScreen();
                testLoc.translate(-3, -3);

                resizeLoc = f.getLocationOnScreen();
                resizeLoc.translate(f.getWidth() - 1, f.getHeight() - 1);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Problem preparing test GUI.");
    }
    // run robot
    Robot robot = Util.createRobot();
    robot.setAutoDelay(ROBOT_DELAY);

    robot.mouseMove(hLoc.x, hLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    robot.mouseMove(vLoc.x, vLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    clickAndBlink(robot, testLoc, false);
    robot.mouseMove(resizeLoc.x, resizeLoc.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseMove(resizeLoc.x + 5, resizeLoc.y + 5);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    Util.waitForIdle(robot);

    clickAndBlink(robot, testLoc, false);
    return frameClicked == 2;
}
 
Example 20
Source File: bug8136998.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public bug8136998() throws AWTException {
    robot = new Robot();
    robot.setAutoDelay(200);
}