From 89754421a293f8882b6b7cb4f632d5a027c67db6 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Thu, 20 Oct 2016 23:14:05 +0200 Subject: [PATCH] Refactor Screenshot examples 2 --- .../com/baeldung/printscreen/Screenshot.java | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/printscreen/Screenshot.java b/core-java/src/main/java/com/baeldung/printscreen/Screenshot.java index 7c29a61842..27fd84e374 100644 --- a/core-java/src/main/java/com/baeldung/printscreen/Screenshot.java +++ b/core-java/src/main/java/com/baeldung/printscreen/Screenshot.java @@ -7,14 +7,10 @@ import java.io.File; public class Screenshot { - private final String filePath; - private final String filenamePrefix; - private final String fileType; + private final String path; - public Screenshot(String filePath, String filenamePrefix, String fileType) { - this.filePath = filePath; - this.filenamePrefix = filenamePrefix; - this.fileType = fileType; + public Screenshot(String path) { + this.path = path; } public void getScreenshot(int timeToWait) throws Exception { @@ -22,14 +18,6 @@ public class Screenshot { Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); Robot robot = new Robot(); BufferedImage img = robot.createScreenCapture(rectangle); - ImageIO.write(img, fileType, setupFileNamePath()); - } - - private File setupFileNamePath() { - return new File(filePath + filenamePrefix + "." + fileType); - } - - private Rectangle getScreenSizedRectangle(final Dimension d) { - return new Rectangle(0, 0, d.width, d.height); + ImageIO.write(img, "jpg", new File(path)); } }