當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。