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


Java Robot.mouseMove方法代码示例

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


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

示例1: clickOnDialog

import java.awt.Robot; //导入方法依赖的package包/类
private static void clickOnDialog(Dialog dialog) {
    try {
        long time = System.currentTimeMillis() + 200;

        while (!dialog.isVisible()) {
            if (time < System.currentTimeMillis()) {
                throw new RuntimeException("Dialog is not visible!");
            }
            Thread.sleep(10);
        }
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.waitForIdle();
        robot.delay(200);

        Point point = getCenterPoint(dialog);

        robot.mouseMove(point.x, point.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:MissingEventsOnModalDialogTest.java

示例2: main

import java.awt.Robot; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    final boolean dump = Boolean.parseBoolean(args[0]);
    final Window w = new Frame() {
        @Override
        public void list(final PrintStream out, final int indent) {
            super.list(out, indent);
            dumped = true;
        }
    };
    w.setSize(200, 200);
    w.setLocationRelativeTo(null);
    w.setVisible(true);

    final Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(w.getX() + w.getWidth() / 2,
                    w.getY() + w.getHeight() / 2);
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    w.dispose();
    if (dumped != dump) {
        throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:DumpOnKey.java

示例3: mouseClickOnComp

import java.awt.Robot; //导入方法依赖的package包/类
static void mouseClickOnComp(Robot r, Component comp) {
    Point loc = comp.getLocationOnScreen();
    loc.x += comp.getWidth() / 2;
    loc.y += comp.getHeight() / 2;
    r.mouseMove(loc.x, loc.y);
    r.delay(10);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.delay(10);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:InputVerifierTest2.java

示例4: enteredGeneratesSameEvents

import java.awt.Robot; //导入方法依赖的package包/类
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    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.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    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(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

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

示例5: releaseGeneratesSameEvents

import java.awt.Robot; //导入方法依赖的package包/类
public void releaseGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_RELEASED;
    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

示例6: test

import java.awt.Robot; //导入方法依赖的package包/类
private static void test(final int mask) throws Exception {
    final Robot r = new Robot();
    r.setAutoDelay(100);
    r.setAutoWaitForIdle(true);

    EventQueue.invokeAndWait(MouseModifiersInKeyEvent::createAndShowGUI);
    r.waitForIdle();
    EventQueue.invokeAndWait(() -> bounds = f.getBounds());

    r.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
    r.mousePress(mask);
    r.keyPress(KeyEvent.VK_A);
    r.keyRelease(KeyEvent.VK_A);

    EventQueue.invokeAndWait(() -> f.dispose());

    r.mouseRelease(mask);

    // all extended modifiers should work
    if (modifiersEX != mask) {
        System.err.println("Expected modifiersEX: " + mask);
        System.err.println("Actual modifiersEX: " + modifiersEX);
        throw new RuntimeException();
    }
    // old modifiers work only for button1
    if (modifiersEX == InputEvent.BUTTON1_DOWN_MASK) {
        if (modifiers != InputEvent.BUTTON1_MASK) {
            System.err.println("Expected modifiers: " + InputEvent.BUTTON1_MASK);
            System.err.println("Actual modifiers: " + modifiers);
            throw new RuntimeException();
        }
    }
    modifiersEX = 0;
    modifiers = 0;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:MouseModifiersInKeyEvent.java

示例7: press

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

示例8: checkAltClickEvent

import java.awt.Robot; //导入方法依赖的package包/类
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());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:37,代码来源:NativeEventsTest.java

示例9: main

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

示例10: init

import java.awt.Robot; //导入方法依赖的package包/类
/**
 * Test fails if it throws any exception.
 *
 * @throws Exception
 */
private void init() throws Exception {

    if (!System.getProperty("os.name").startsWith("Windows")) {
        System.out.println("This is Windows only test.");
        return;
    }

    final Frame frame = new Frame("AWT Frame");
    frame.pack();
    frame.setSize(200, 200);
    FramePeer frame_peer = AWTAccessor.getComponentAccessor()
                                .getPeer(frame);
    Class comp_peer_class
            = Class.forName("sun.awt.windows.WComponentPeer");
    Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
    hwnd_field.setAccessible(true);
    long hwnd = hwnd_field.getLong(frame_peer);

    Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
    Constructor constructor
            = clazz.getConstructor(new Class[]{long.class});
    final Frame embedded_frame
            = (Frame) constructor.newInstance(new Object[]{
                new Long(hwnd)});;
    final JComboBox<String> combo = new JComboBox<>(new String[]{
        "Item 1", "Item 2"
    });
    combo.setSelectedIndex(1);
    final Panel p = new Panel();
    p.setLayout(new BorderLayout());
    embedded_frame.add(p, BorderLayout.CENTER);
    embedded_frame.validate();
    p.add(combo);
    p.validate();
    frame.setVisible(true);
    Robot robot = new Robot();
    robot.delay(2000);
    Rectangle clos = new Rectangle(
            combo.getLocationOnScreen(), combo.getSize());
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (!combo.isPopupVisible()) {
        throw new RuntimeException("Combobox popup is not visible!");
    }
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (combo.getSelectedIndex() != 0) {
        throw new RuntimeException("Combobox selection has not changed!");
    }
    embedded_frame.remove(p);
    embedded_frame.dispose();
    frame.dispose();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:EmbeddedFrameGrabTest.java

示例11: 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(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

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

        robot.waitForIdle();

        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);
        robot.waitForIdle();

        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);
        robot.waitForIdle();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:SelectionInvisibleTest.java

示例12: mouseClick

import java.awt.Robot; //导入方法依赖的package包/类
@Override
public void mouseClick(int x, int y) {
    try {
        Robot robot = new Robot();
        
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    } catch (AWTException ex) {
        Logger.getLogger(Automator.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:13,代码来源:Automator.java

示例13: main

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

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:bug6505523.java

示例14: TestPopupMenu

import java.awt.Robot; //导入方法依赖的package包/类
public TestPopupMenu() throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(200);
    try {
        SwingUtilities.invokeAndWait(() -> {
            try {
                createAndShowUI();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        blockTillDisplayed(label);
        robot.waitForIdle();
        robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
        robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.waitForIdle();
        JPopupMenu popup = label.getComponentPopupMenu();
        if (popup != null && popup.isVisible()) {
            throw new RuntimeException("Popup is visible in wrong internal frame");
        }
    } finally {
        SwingUtilities.invokeAndWait(()->frame.dispose());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:TestPopupMenu.java

示例15: pointOnComp

import java.awt.Robot; //导入方法依赖的package包/类
/**
 * Moves mouse pointer in the center of given {@code comp} component
 * using {@code robot} parameter.
 */
public static void pointOnComp(final Component comp, final Robot robot) {
    Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
    robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:Util.java


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