当前位置: 首页>>代码示例>>Java>>正文


Java Robot类代码示例

本文整理汇总了Java中java.awt.Robot的典型用法代码示例。如果您正苦于以下问题:Java Robot类的具体用法?Java Robot怎么用?Java Robot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Robot类属于java.awt包,在下文中一共展示了Robot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.awt.Robot; //导入依赖的package包/类
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();
            }
        });
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:SetShapeTest.java

示例2: main

import java.awt.Robot; //导入依赖的package包/类
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();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:MissingDragExitEventTest.java

示例3: ScreenCut

import java.awt.Robot; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:ajtdnyy,项目名称:ScreenCut,代码行数:31,代码来源:ScreenCut.java

示例4: singleClickGeneratesSameEvents

import java.awt.Robot; //导入依赖的package包/类
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());

}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:41,代码来源:NativeEventsTest.java

示例5: performTest

import java.awt.Robot; //导入依赖的package包/类
@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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:JSplitPaneOverlapping.java

示例6: main

import java.awt.Robot; //导入依赖的package包/类
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());
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:bug8017284.java

示例7: main

import java.awt.Robot; //导入依赖的package包/类
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);
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:KeyCharTest.java

示例8: main

import java.awt.Robot; //导入依赖的package包/类
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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:MenuItemIconTest.java

示例9: main

import java.awt.Robot; //导入依赖的package包/类
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();
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:DeadKeySystemAssertionDialog.java

示例10: enterInput

import java.awt.Robot; //导入依赖的package包/类
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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:MissingCharsKorean.java

示例11: main

import java.awt.Robot; //导入依赖的package包/类
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);
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:KeyCharTest.java

示例12: captureImage

import java.awt.Robot; //导入依赖的package包/类
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;
}
 
开发者ID:mhusam,项目名称:ChessBot,代码行数:17,代码来源:ImageUtils.java

示例13: main

import java.awt.Robot; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:bug7055065.java

示例14: ActionEventTest

import java.awt.Robot; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ActionEventTest.java

示例15: OverScrollTest

import java.awt.Robot; //导入依赖的package包/类
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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:OverScrollTest.java


注:本文中的java.awt.Robot类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。