Java Code Examples for java.awt.Robot#delay()
The following examples show how to use
java.awt.Robot#delay() .
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: ImageDecoratedDnDNegative.java From hottub with GNU General Public License v2.0 | 6 votes |
public void moveTo( Robot r, Point b, Point e) { Point2D.Double ee = new Point2D.Double(e.getX(), e.getY()); Point2D.Double bb = new Point2D.Double(b.getX(), b.getY()); final int count = (int)(ee.distance(bb)); Point2D.Double c = new Point2D.Double(bb.getX(), bb.getY()); for(int i=0; i<count; ++i){ c.setLocation( bb.getX() + (ee.getX()-bb.getX())*i/count, bb.getY() + (ee.getY()-bb.getY())*i/count); r.mouseMove( (int)c.getX(), (int)c.getY()); r.delay(5); } r.mouseMove( (int)ee.getX(), (int)ee.getY()); r.delay(5); }
Example 2
Source File: TestJInternalFrameMaximize.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { robot = new Robot(); UIManager.LookAndFeelInfo[] lookAndFeelArray = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) { String lookAndFeelString = lookAndFeelItem.getClassName(); if (tryLookAndFeel(lookAndFeelString)) { createUI(); robot.waitForIdle(); executeTest(); robot.delay(1000); } } if (!"".equals(errorMessage)) { throw new RuntimeException(errorMessage); } }
Example 3
Source File: Util.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void clickOnTitle(final Window decoratedWindow, final Robot robot) { if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) { Point p = getTitlePoint(decoratedWindow); robot.mouseMove(p.x, p.y); robot.delay(50); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); robot.mouseRelease(InputEvent.BUTTON1_MASK); } }
Example 4
Source File: Util.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void clickOnTitle(final Window decoratedWindow, final Robot robot) { if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) { Point p = getTitlePoint(decoratedWindow); robot.mouseMove(p.x, p.y); robot.delay(50); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); robot.mouseRelease(InputEvent.BUTTON1_MASK); } }
Example 5
Source File: EndlessLoopTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); }
Example 6
Source File: Util.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void clickOnTitle(final Window decoratedWindow, final Robot robot) { if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) { Point p = getTitlePoint(decoratedWindow); robot.mouseMove(p.x, p.y); robot.delay(50); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); robot.mouseRelease(InputEvent.BUTTON1_MASK); } }
Example 7
Source File: ScrollableTabbedPaneTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { robot = new Robot(); robot.delay(1000); UIManager.LookAndFeelInfo[] lookAndFeelArray = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) { executeCase(lookAndFeelItem.getClassName(), lookAndFeelItem.getName()); } if (!"".equals(errorString)) { throw new RuntimeException("Error Log:\n" + errorString); } }
Example 8
Source File: TestJInternalFrameDispose.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { createUI(); } }); robot.waitForIdle(); executeTest(); robot.delay(1000); dispose(); }
Example 9
Source File: bug4936917.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void init() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { editorPane = new JEditorPane("text/html", ""); editorPane.setEditable(false); editorPane.setMargin(new java.awt.Insets(0, 0, 0, 0)); editorPane.setText(text); f = new JFrame(); f.getContentPane().add(editorPane); f.setSize(600, 400); f.setVisible(true); } }); blockTillDisplayed(editorPane); Robot robot = new Robot(); robot.waitForIdle(); robot.delay(300); int x0 = p.x + 15 ; int y = p.y + 15; int match = 0; int nonmatch = 0; passed = true; for (int x = x0; x < x0 + 10; x++) { System.out.println("color ("+x+"," + y +")=" + robot.getPixelColor(x,y)); if (!robot.getPixelColor(x, y).equals(new Color(0xcc, 0xcc, 0xcc))) { nonmatch++; } else match++; } if (nonmatch > match) { passed = false; } }
Example 10
Source File: Util.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void clickOnTitle(final Window decoratedWindow, final Robot robot) { if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) { Point p = getTitlePoint(decoratedWindow); robot.mouseMove(p.x, p.y); robot.delay(50); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); robot.mouseRelease(InputEvent.BUTTON1_MASK); } }
Example 11
Source File: MutterMaximizeTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private static void rdown(Robot robot) { robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); }
Example 12
Source File: MutterMaximizeTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private static void rdown(Robot robot) { robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); }
Example 13
Source File: ResetMostRecentFocusOwnerTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public void start() { Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent e) { System.err.println(e); } }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK); boolean gained = false; final Robot robot = Util.createRobot(); JFrame frame1 = new JFrame("Main Frame"); final JButton b1 = new JButton("button1"); frame1.add(b1); frame1.pack(); frame1.setLocation(0, 300); Util.showWindowWait(frame1); final JFrame frame2 = new JFrame("Test Frame"); final JButton b2 = new JButton("button2"); frame2.add(b2); frame2.pack(); frame2.setLocation(300, 300); b2.setEnabled(false); b2.requestFocus(); Util.showWindowWait(frame2); robot.delay(500); // // It's expeced that the focus is restored to <button1>. // If not, click <button1> to set focus on it. // if (!b1.hasFocus()) { gained = Util.trackFocusGained(b1, new Runnable() { public void run() { Util.clickOnComp(b1, robot); } }, 5000, false); if (!gained) { throw new RuntimeException("Unexpected state: focus is not on <button1>"); } } robot.delay(500); // // Click <button2>, check that focus is set on the parent frame. // gained = false; gained = Util.trackFocusGained(frame2, new Runnable() { public void run() { Util.clickOnComp(b2, robot); } }, 5000, false); if (!gained) { throw new RuntimeException("Test failed: focus wasn't set to <frame2>"); } System.out.println("Test passed."); }
Example 14
Source File: MutterMaximizeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void rdown(Robot robot) { robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); }
Example 15
Source File: bug8016356.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { // Windows only test if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { // Retrieving top edge of Desktop GraphicsConfiguration grConf = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Rectangle scrRect = grConf.getBounds(); Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf); scrTop = scrRect.y + scrInsets.top; color = new Color(0, 255, 0); SwingUtilities.invokeAndWait(() -> { createAndShowUI(); }); try { Robot robot = new Robot(); robot.setAutoDelay(500); robot.setAutoWaitForIdle(true); robot.delay(1000); // Resizing a window to invoke Windows Snap feature readFrameInfo(); robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseMove(frLoc.x + frSize.width / 2, scrTop); robot.mouseRelease(InputEvent.BUTTON1_MASK); // Retrieving the color of window expanded area readFrameInfo(); Insets insets = frame.getInsets(); Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2, frLoc.y + frSize.height - insets.bottom - 1); frame.dispose(); if (!bgColor.equals(color)) { throw new RuntimeException("TEST FAILED: got " + bgColor + " instead of " + color); } System.out.println("TEST PASSED!"); } catch (AWTException ex) { throw new RuntimeException("TEST FAILED!"); } } }
Example 16
Source File: MutterMaximizeTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private static void rup(Robot robot) { robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(50); }
Example 17
Source File: MutterMaximizeTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private static void rdown(Robot robot) { robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); }
Example 18
Source File: MutterMaximizeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void rup(Robot robot) { robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(50); }
Example 19
Source File: Util.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Tests whether screen pixel has the expected color performing several * attempts. This method is useful for asynchronous window manager where * it's impossible to determine when drawing actually takes place. * * @param x X position of pixel * @param y Y position of pixel * @param color expected color * @param attempts number of attempts to undertake * @param delay delay before each attempt * @param robot a robot to use for retrieving pixel color * @return true if pixel color matches the color expected, otherwise false */ public static boolean testPixelColor(int x, int y, final Color color, int attempts, int delay, final Robot robot) { while (attempts-- > 0) { robot.delay(delay); Color screen = robot.getPixelColor(x, y); if (screen.equals(color)) { return true; } } return false; }
Example 20
Source File: Util.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Tests whether screen pixel has the expected color performing several * attempts. This method is useful for asynchronous window manager where * it's impossible to determine when drawing actually takes place. * * @param x X position of pixel * @param y Y position of pixel * @param color expected color * @param attempts number of attempts to undertake * @param delay delay before each attempt * @param robot a robot to use for retrieving pixel color * @return true if pixel color matches the color expected, otherwise false */ public static boolean testPixelColor(int x, int y, final Color color, int attempts, int delay, final Robot robot) { while (attempts-- > 0) { robot.delay(delay); Color screen = robot.getPixelColor(x, y); if (screen.equals(color)) { return true; } } return false; }