Java 类java.awt.Robot 实例源码

项目:openjdk-jdk10    文件:SetShapeTest.java   
public static void main(String[] args) throws Exception {
    createUI();
    Robot robot = new Robot();
    robot.waitForIdle();
    Rectangle rect = window.getBounds();
    rect.x += rect.width - 10;
    rect.y += rect.height - 10;
    robot.delay(1000);
    Color c = robot.getPixelColor(rect.x, rect.y);
    try {
        if (!c.equals(Color.RED)) {
            throw new RuntimeException("Test Failed");
        }
    } finally {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                background.dispose();
                window.dispose();
            }
        });
    }
}
项目:ScreenCut    文件:ScreenCut.java   
/**
 * Creates new form ScreenCut
 *
 * @param parent
 * @param modal
 */
public ScreenCut(java.awt.Frame parent, boolean modal) {
    initComponents();
    addMouseListener(this);
    addMouseMotionListener(this);
    toolbar.setVisible(false);
    panel.setVisible(false);
    text.setVisible(false);
    try {
        robot = new Robot();
        screen = new Rectangle(tool.getScreenSize());
        setSize(screen.width, screen.height);
        bgimg = robot.createScreenCapture(screen);
        cur = tool.createCustomCursor(tool.createImage(getClass().getResource("/cur.png")), new Point(0, 0), "cur");
        setCursor(cur);
        ButtonGroup bg = new ButtonGroup();
        bg.add(size1);
        bg.add(size2);
        bg.add(size3);
        initActionListener(panel.getComponents());
        initActionListener(toolbar.getComponents());
    } catch (AWTException ex) {
        Logger.getLogger(ScreenCut.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:openjdk-jdk10    文件:KeyCharTest.java   
public static void main(String[] args) throws Exception {


        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.waitForIdle();


        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        robot.waitForIdle();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
项目: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);
    }
}
项目:openjdk-jdk10    文件:DeadKeySystemAssertionDialog.java   
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

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

        frame.setVisible(true);
        robot.waitForIdle();

        textField.requestFocus();
        robot.waitForIdle();

        // Check that the system assertion dialog does not block Java
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        frame.setVisible(false);
        frame.dispose();
    }
项目:openjdk-jdk10    文件:MissingCharsKorean.java   
private static void enterInput(Robot robotKeyInput, int keyInputs[][]) {
    for (int i = 0; i < keyInputs.length; i++) {
        String strKeyInput = "KeyPress=>";
        final int noOfKeyInputs = keyInputs[i].length;
        for (int j = 0; j < noOfKeyInputs; j++) {
            robotKeyInput.keyPress(keyInputs[i][j]);
            strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
        }

        strKeyInput += "KeyRelease=>";
        for (int j = noOfKeyInputs - 1; j >= 0; j--) {
            robotKeyInput.keyRelease(keyInputs[i][j]);
            strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
        }
        System.out.println(strKeyInput);
    }
}
项目:jdk8u-jdk    文件:KeyCharTest.java   
public static void main(String[] args) throws Exception {

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

        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        toolkit.realSync();

        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        toolkit.realSync();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
项目:ChessBot    文件:ImageUtils.java   
public static BufferedImage captureImage() {
    try {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        Robot rt = new Robot();
        BufferedImage img = rt.createScreenCapture(
                new Rectangle(DesktopScreenRecorder.CAPTURE_1_X, 
                        DesktopScreenRecorder.CAPTURE_1_Y, 
                        DesktopScreenRecorder.CAPTURE_2_X, 
                        DesktopScreenRecorder.CAPTURE_2_Y));

        return img;
    } catch (Exception e) {
        UIUtils.popupError(e, "ImageUtils::writeImage");
    }
    return null;
}
项目:jdk8u-jdk    文件:MissingDragExitEventTest.java   
public static void main(final String[] args) throws Exception {
    try {
        final Robot r = new Robot();
        r.setAutoDelay(50);
        r.mouseMove(100, 100);
        Util.waitForIdle(r);

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

        final Point inside = new Point(frame.getLocationOnScreen());
        inside.translate(20, SIZE / 2);
        final Point outer = new Point(inside);
        outer.translate(-40, 0);
        r.mouseMove(inside.x, inside.y);
        r.mousePress(InputEvent.BUTTON1_MASK);
        try {
            for (int i = 0; i < 3; ++i) {
                Util.mouseMove(r, inside, outer);
                Util.mouseMove(r, outer, inside);
            }
        } finally {
            r.mouseRelease(InputEvent.BUTTON1_MASK);
        }
        sleep();

        if (FAILED || !MOUSE_ENTERED || !MOUSE_ENTERED_DT || !MOUSE_EXIT
                || !MOUSE_EXIT_TD) {
            throw new RuntimeException("Failed");
        }
    } finally {
        if (frame != null) {
            frame.dispose();
        }
    }
}
项目:openjdk-jdk10    文件:SelectAllFilesFilterTest.java   
public static void main(String[] args) throws Exception {

        SwingUtilities.invokeLater(SelectAllFilesFilterTest::createAndShowGUI);

        while (fileChooser == null) {
            Thread.sleep(100);
        }

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

        SwingUtilities.invokeAndWait(() -> {
            comboBox = findComboBox(fileChooser);
            comboBox.setSelectedIndex(0);
        });
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            int selectedIndex = comboBox.getSelectedIndex();
            fileChooser.setVisible(false);

            if (selectedIndex != 0) {
                throw new RuntimeException("Select All file filter is not selected!");
            }
        });
    }
项目:incubator-netbeans    文件:Find.java   
/** Performs simple test of Find
 * @param args the command line arguments
 */
public static void main(String args[]) {
    new Find().verify();
    System.out.println("Find verification finished.");
    try {
        Robot robot=new Robot();
        System.out.println("Start delay.");
        robot.delay(2000);
        System.out.println("Delayed");
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.delay(1);
        robot.keyPress(KeyEvent.VK_F);
        robot.delay(20);
        robot.keyRelease(KeyEvent.VK_F);
        robot.delay(1);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        System.out.println("1");
        robot.waitForIdle();
        System.out.println("2");
        Find.find("aaa",robot);
        System.out.println("3");

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:jdk8u-jdk    文件:SelectionInvisibleTest.java   
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!");
        }
    }
项目:phoenix.webui.framework    文件:AwtMouse.java   
@Override
public void click()
{
    try
    {
        Robot robot = new Robot();
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    }
    catch (AWTException e)
    {
        e.printStackTrace();
    }
}
项目:openjdk-jdk10    文件:bug4846413.java   
public static void main(String[] args) throws Exception {

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

        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {

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

        robot.waitForIdle();

        Point movePoint = getButtonPoint();
        robot.mouseMove(movePoint.x, movePoint.y);
        robot.waitForIdle();

        long timeout = System.currentTimeMillis() + 9000;
        while (!isTooltipAdded && (System.currentTimeMillis() < timeout)) {
            try {Thread.sleep(500);} catch (Exception e) {}
        }

        checkToolTip();
    }
项目:marathonv5    文件:NativeEventsTest.java   
private void checkAltClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    tclear();
    Point locationButton = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension sizeButton = EventQueueWait.call_noexc(button, "getSize");
    Point locationTextArea = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension sizeTextArea = EventQueueWait.call_noexc(actionsArea, "getSize");

    Robot robot = new Robot();
    robot.setAutoDelay(10);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseMove(locationButton.x + sizeButton.width / 2 + 1, locationButton.y + sizeButton.height / 2 + 1);
    robot.mouseMove(locationButton.x + sizeButton.width / 2, locationButton.y + sizeButton.height / 2);
    robot.keyPress(KeyEvent.VK_ALT);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = weTextArea.getText();
    tclear();
    System.err.println("================================");
    System.err.println(expected);
    System.err.println("=================================");
    new Actions(driver).moveToElement(weButton).keyDown(Keys.ALT).click().keyUp(Keys.ALT).moveToElement(weTextArea).perform();
    AssertJUnit.assertEquals(expected, weTextArea.getText());
}
项目:openjdk-jdk10    文件:MutterMaximizeTest.java   
private static Thread startRegTest(final Frame f) {
    Thread robot = new Thread(new Runnable() {
        public void run() {
            Robot r = Util.createRobot();
            dragWindow(f, 100, 100, r);
            // wait for the location to be set.
            sleepFor(2000);

            final Point l2 = f.getLocationOnScreen();

            // double click should maximize the frame
            doubleClick(r);

            // wait for location again.
            sleepFor(2000);
            final Point l3 = f.getLocationOnScreen();
            if (l3.equals(l2)) {
                throw new RuntimeException("Bad location after maximize. Window location has not moved");
            }
        }
    });
    return robot;
}
项目:openjdk-jdk10    文件:RobotCrash.java   
public void robotKeyPressTest() throws Exception {

        SwingUtilities.invokeAndWait(() -> {
            frame = new Frame();
            frame.setSize(300, 300);
            frame.setVisible(true);
        });

        Robot robot = new Robot();
        robot.waitForIdle();
        Point pt = frame.getLocationOnScreen();
        robot.mouseMove(((int) pt.getX() + frame.getWidth()) / 2,
                ((int) pt.getY() + frame.getHeight()) / 2);
        robot.waitForIdle();
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.waitForIdle();
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            frame.dispose();
        });
    }
项目:marathonv5    文件:NativeEventsTest.java   
public void rightClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).contextClick().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
项目:marathonv5    文件:NativeEventsTest.java   
public void singleClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    AssertJUnit.assertEquals(expected, t.getText());

    tclear();
    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
项目:jdk8u-jdk    文件:bug4524490.java   
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();
}
项目:jdk8u-jdk    文件:DrawImageBilinear.java   
private static void doCapture(Component test) {
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    // Grab the screen region
    try {
        Robot robot = new Robot();
        Point pt1 = test.getLocationOnScreen();
        Rectangle rect =
            new Rectangle(pt1.x, pt1.y, test.getWidth(), test.getHeight());
        capture = robot.createScreenCapture(rect);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:openjdk-jdk10    文件:JemmyExt.java   
public static void waitImageIsStill(Robot rob, ComponentOperator operator) {
    operator.waitState(new ComponentChooser() {

        private BufferedImage previousImage = null;
        private int index = 0;
        private final StrictImageComparator sComparator = new StrictImageComparator();

        @Override
        public boolean checkComponent(Component comp) {
            BufferedImage currentImage = capture(rob, operator);
            save(currentImage, "waitImageIsStill" + index + ".png");
            index++;
            boolean compareResult = previousImage == null ? false : sComparator.compare(currentImage, previousImage);
            previousImage = currentImage;
            return compareResult;
        }

        @Override
        public String getDescription() {
            return "Image of " + operator + " is still";
        }
    });
}
项目:jdk8u-jdk    文件:TestBadBreak.java   
public static void main(final String[] args) throws Exception {
    robot = new Robot();
    final BufferedImage bi1 = new BufferedImage(200, 90, TYPE_INT_ARGB);
    final BufferedImage bi2 = new BufferedImage(200, 90, TYPE_INT_ARGB);
    test(withCombiningDiaeresis, bi1);
    test(withoutCombiningDiaeresis, bi2);
    for (int x = 0; x < bi1.getWidth(); ++x) {
        for (int y = 0; y < bi1.getHeight(); ++y) {
            if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
                ImageIO.write(bi1, "png", new File("image1.png"));
                ImageIO.write(bi2, "png", new File("image2.png"));
                throw new RuntimeException("Wrong color");
            }
        }
    }
}
项目:jdk8u-jdk    文件:PaintNativeOnUpdate.java   
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();
}
项目:geomapapp    文件:XMLJTreeDialog.java   
public void mouseClicked(MouseEvent e) {
    if (SwingUtilities.isRightMouseButton(e)) {
        try {
            Robot robot = new java.awt.Robot();
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
        } catch (AWTException ex) {
            System.out.println(ex);
        }
    }
}
项目:openjdk-jdk10    文件:AutoScrollOnSelectAndAppend.java   
public AutoScrollOnSelectAndAppend() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException("Robot Creation Failed.");
    }
    frame = new Frame();
    frame.setSize(200, 200);
    frame.setLayout(new FlowLayout());

    textArea = new TextArea(5, 20);
    composeTextArea();
    frame.add(textArea);

    buttonHoldFocus = new Button("HoldFocus");
    frame.add(buttonHoldFocus);

    frame.setVisible(true);
    robot.waitForIdle();

    // Move mouse cursor on first row of text area.
    Point loc = textArea.getLocationOnScreen();
    robot.mouseMove(loc.x + 8, loc.y + 8);
    robot.waitForIdle();
}
项目:openjdk-jdk10    文件:EditPadTest.java   
@BeforeClass
public static void setUpEditorPadTest() {
    if (!GraphicsEnvironment.isHeadless()) {
        try {
            robot = new Robot();
            robot.setAutoWaitForIdle(true);
            robot.setAutoDelay(DELAY);
        } catch (AWTException e) {
            throw new ExceptionInInitializerError(e);
        }
    }
}
项目:openjdk-jdk10    文件:bug6219960.java   
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    SwingUtilities.invokeAndWait(bug6219960::createAndShowGUI);
    robot.waitForIdle();
    showModal("The tooltip should be showing. Press ok with mouse. And don't move it.");
    robot.waitForIdle();
    showModal("Now press ok and move the mouse inside the table (don't leave it).");
    robot.waitForIdle();
}
项目:jdk8u-jdk    文件:MultiResolutionSplashTest.java   
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
项目:openjdk-jdk10    文件:Test8051548.java   
static void testShowDialog(boolean colorTransparencySelectionEnabled) throws Exception {
    int alphaValue = 123;
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SwingUtilities.invokeLater(() -> {
        color = JColorChooser.showDialog(null, "Change Color",
                new Color(10, 20, 30, alphaValue),
                colorTransparencySelectionEnabled);
    });

    SwingUtilities.invokeAndWait(() -> {
        // wait for dialog is shown
    });

    robot.waitForIdle();

    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    robot.waitForIdle();

    if (colorTransparencySelectionEnabled) {
        if (color.getAlpha() != alphaValue) {
            throw new RuntimeException("Color alpha has not bee reseted!");
        }
    } else {
        if (color.getAlpha() != 255) {
            throw new RuntimeException("Color alpha has not bee reseted!");
        }
    }
}
项目:jdk8u-jdk    文件:bug6505523.java   
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            createAndShowGUI();
        }
    });

    toolkit.realSync();

    Point point = getRowPointToClick(2);
    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    toolkit.realSync();

}
项目:openjdk-jdk10    文件:DrawImageBilinear.java   
private static void doCapture(Component test) {
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    // Grab the screen region
    try {
        Robot robot = new Robot();
        Point pt1 = test.getLocationOnScreen();
        Rectangle rect =
            new Rectangle(pt1.x, pt1.y, test.getWidth(), test.getHeight());
        capture = robot.createScreenCapture(rect);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:openjdk-jdk10    文件:PressedButtonRightClickTest.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("Exception in Robot creation");
        }

        testRobot.waitForIdle();

        // Method performing auto test operation
        test();

        disposeTestUI();
    }
项目:openjdk-jdk10    文件:TestJInternalFrameIconify.java   
public static void main(String[] args) throws Exception {
    robot = new java.awt.Robot();
    UIManager.LookAndFeelInfo[] lookAndFeelArray
            = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
        String lookAndFeelString = lookAndFeelItem.getClassName();
        if (tryLookAndFeel(lookAndFeelString)) {
            createUI(lookAndFeelString);
            robot.waitForIdle();
            executeTest(lookAndFeelString);
        }
    }
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
项目:TypeFast    文件:TypeFast.java   
public static void main(String[] args) throws Exception {
    String line;
    if (args.length == 0) {
        System.out.println("Enter the line to repeat:");
        line = scan.nextLine();
    } else {
        StringBuilder sb = new StringBuilder();
        for (String a : args)
            sb.append(a + " ");
        line = sb.toString();
    }
    System.out.println("Press Enter to proceed to 3s count down.");
    scan.nextLine();
    Robot robot = new Robot();
    Thread.sleep(3000);
    writeString(line, robot);
}
项目:openjdk-jdk10    文件: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);
}
项目:openjdk-jdk10    文件:JSplitPaneOverlapping.java   
@Override
protected boolean performTest() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                splitterLoc = sp2.getLocationOnScreen();
                Point leftLoc = sp1.getLocationOnScreen();
                leftLoc.translate(sp1.getWidth(), 0);
                splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Where is splitter?");
    }
    // run robot
    Robot robot = Util.createRobot();
    robot.setAutoDelay(ROBOT_DELAY);

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

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);
    Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);
    System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);
    if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {
        fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    clickAndBlink(robot, splitterLoc);

    return clicked;
}
项目:openjdk-jdk10    文件:ActionEventTest.java   
public ActionEventTest() {
    try {
        robot = new Robot();
        robot.setAutoDelay(100);
        robot.setAutoWaitForIdle(true);
    } catch(AWTException e) {
        throw new RuntimeException(e.getMessage());
    }

    list = new List(1, false);
    list.add("0");
    add(list);
    setSize(400,400);
    setLayout(new FlowLayout());
    pack();
    setVisible(true);
}
项目:openjdk-jdk10    文件:OverScrollTest.java   
OverScrollTest() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }

    mainFrame = new Frame();
    mainFrame.setSize(400, 200);
    mainFrame.setLocation(200, 200);
    mainFrame.setLayout(new FlowLayout());

    textArea = new TextArea(2, 10);
    textArea.setSize(300, 100);
    textArea.setText("123456 789123");
    mainFrame.add(textArea);
    mainFrame.setVisible(true);
    textArea.requestFocusInWindow();
}
项目:voicemenu    文件:Event_TransformationMenu.java   
@Override
public void execute(@NotNull String pattern) {

  try {
    Robot r = new Robot();
    r.keyPress(157);
    r.keyPress(90);

    r.keyRelease(90);
    r.keyRelease(157);

  } catch (AWTException e) {
    e.printStackTrace();
  }
  SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
  SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);

}