create Robot - Java java.awt

Java examples for java.awt:Robot

Description

create Robot

Demo Code


//package com.java2s;
import java.awt.AWTException;

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import java.awt.MouseInfo;

import java.awt.Robot;

import java.util.concurrent.atomic.AtomicReference;

public class Main {
    public static Robot createRobot(GraphicsDevice device) {
        try {/*from www .j  av a 2  s  .c om*/
            return new Robot(device);
        } catch (AWTException e) {
            throw new RuntimeException("createRobot", e);
        }
    }

    public static Robot createRobot(
            AtomicReference<GraphicsDevice> deviceRef) {
        GraphicsDevice device = getMouseScreen();
        deviceRef.set(device);
        return createRobot(device);
    }

    public static GraphicsDevice getMouseScreen() {
        return MouseInfo.getPointerInfo().getDevice();
    }

    public static GraphicsDevice getDevice(int screenNo)
            throws AWTException {
        GraphicsEnvironment env = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        GraphicsDevice device = env.getScreenDevices()[screenNo];
        return device;
    }
}

Related Tutorials