Example usage for java.awt Robot Robot

List of usage examples for java.awt Robot Robot

Introduction

In this page you can find the example usage for java.awt Robot Robot.

Prototype

public Robot(GraphicsDevice screen) throws AWTException 

Source Link

Document

Creates a Robot for the given screen device.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int i = 0; i < gs.length; i++) {
        Robot robot = new Robot(gs[i]);

    }/*from w  ww  . j  a va2s .  c  o  m*/
}

From source file:RobotTest.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            // make frame with a button panel

            ButtonFrame frame = new ButtonFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);/*www. j a v  a2s  . c o  m*/

            // attach a robot to the screen device

            GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice screen = environment.getDefaultScreenDevice();

            try {
                Robot robot = new Robot(screen);
                runTest(robot);
            } catch (AWTException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:org.pentaho.reporting.designer.core.actions.global.ScreenCaptureAction.java

public static void saveScreenShot(final int modifiers) {
    final Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    final GraphicsConfiguration graphicsConfiguration = component.getGraphicsConfiguration();
    final GraphicsDevice graphicsDevice = graphicsConfiguration.getDevice();
    try {//  ww  w.j  ava2  s .  c o m
        final Robot robot = new Robot(graphicsDevice);
        final BufferedImage image;
        if ((modifiers & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK) {
            image = robot.createScreenCapture(graphicsConfiguration.getBounds());
        } else {
            image = robot.createScreenCapture(component.getBounds());
        }

        final String homeDirectory = ReportDesignerBoot.getInstance().getGlobalConfig()
                .getConfigProperty("user.home", ".");
        final File homeDir = new File(homeDirectory);
        final File f = generateName(homeDir);
        if (f == null) {
            return;
        }
        final FileOutputStream fout = new FileOutputStream(f);
        try {
            final PngEncoder encoder = new PngEncoder();
            encoder.setCompressionLevel(6);
            encoder.setEncodeAlpha(false);
            encoder.setImage(image);
            final byte[] bytes = encoder.pngEncode();
            fout.write(bytes);
        } finally {
            fout.close();
        }
    } catch (IOException ioe) {
        UncaughtExceptionsModel.getInstance().addException(ioe);
    } catch (AWTException e1) {
        // ignore
        UncaughtExceptionsModel.getInstance().addException(e1);
    }
}

From source file:net.sradonia.gui.SplashScreen.java

/**
 * Re-captures the splash's background and redraws the buffered picture.
 *///from   www. jav a 2s . c o m
private void updateSplash() {
    try {
        splash = new Robot(window.getGraphicsConfiguration().getDevice())
                .createScreenCapture(window.getBounds());
        splash.createGraphics().drawImage(image, 0, 0, window);
    } catch (AWTException e) {
    }
}