本文整理汇总了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();
}
});
}
}
示例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();
}
}
}
示例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);
}
}
示例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());
}
示例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;
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}