From 7bef78afcc90c7f5c9b86d4c3723fe111407540c Mon Sep 17 00:00:00 2001 From: Hronom Date: Sun, 24 Apr 2016 14:51:31 +0300 Subject: [PATCH] Add GUI --- robocraft-assistant-app/pom.xml | 16 +- .../hronom/robocraft/assistant/app/App.java | 30 --- .../assistant/app/RobocraftAssistantApp.java | 209 ++++++++++++++++++ .../app/controllers/ShootController.java | 22 ++ .../assistant/app/models/ShooterModel.java | 29 +++ .../app/views/AssistantMainView.java | 46 ++++ .../assistant/app/views/ShootView.java | 146 ++++++++++++ .../app/views/1461511403_robot_64.png | Bin 0 -> 5689 bytes .../src/main/resources/log4j2.xml | 24 ++ .../robocraft/assistant/core/Shooter.java | 72 +++--- 10 files changed, 520 insertions(+), 74 deletions(-) delete mode 100755 robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/App.java create mode 100755 robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/RobocraftAssistantApp.java create mode 100644 robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/controllers/ShootController.java create mode 100644 robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/models/ShooterModel.java create mode 100755 robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/AssistantMainView.java create mode 100755 robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/ShootView.java create mode 100644 robocraft-assistant-app/src/main/resources/com/github/hronom/robocraft/assistant/app/views/1461511403_robot_64.png create mode 100755 robocraft-assistant-app/src/main/resources/log4j2.xml diff --git a/robocraft-assistant-app/pom.xml b/robocraft-assistant-app/pom.xml index 1904234..09c3be1 100644 --- a/robocraft-assistant-app/pom.xml +++ b/robocraft-assistant-app/pom.xml @@ -12,7 +12,6 @@ jar robocraft-assistant-app - http://maven.apache.org @@ -20,6 +19,17 @@ robocraft-assistant-core 1.0.0 + + + org.apache.logging.log4j + log4j-api + 2.5 + + + org.apache.logging.log4j + log4j-core + 2.5 + junit @@ -55,7 +65,7 @@ true lib simple - com.github.hronom.robocraft.assistant.app.App + com.github.hronom.robocraft.assistant.app.RobocraftAssistantApp true true @@ -190,7 +200,7 @@ TODO src/main/icons/1461509409_robot_64.ico - com.github.hronom.robocraft.assistant.app.App + com.github.hronom.robocraft.assistant.app.RobocraftAssistantApp true anything diff --git a/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/App.java b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/App.java deleted file mode 100755 index f0c0174..0000000 --- a/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/App.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.hronom.robocraft.assistant.app; - -import com.github.hronom.robocraft.assistant.core.Shooter; -import com.tulskiy.keymaster.common.HotKey; -import com.tulskiy.keymaster.common.HotKeyListener; -import com.tulskiy.keymaster.common.Provider; - -import java.awt.*; -import java.awt.event.KeyEvent; -import java.util.concurrent.TimeUnit; - -import javax.swing.*; - -public class App { - public static void main(String[] args) throws InterruptedException, AWTException { - final Shooter shooter = new Shooter(); - - Provider provider = Provider.getCurrentProvider(true); - provider.register(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0), new HotKeyListener() { - public void onHotKey(HotKey hotKey) { - shooter.toggle(); - } - }); - - Thread.sleep(TimeUnit.DAYS.toMillis(1000)); - - provider.reset(); - provider.stop(); - } -} diff --git a/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/RobocraftAssistantApp.java b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/RobocraftAssistantApp.java new file mode 100755 index 0000000..9c6f6e0 --- /dev/null +++ b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/RobocraftAssistantApp.java @@ -0,0 +1,209 @@ +package com.github.hronom.robocraft.assistant.app; + +import com.github.hronom.robocraft.assistant.app.controllers.ShootController; +import com.github.hronom.robocraft.assistant.app.models.ShooterModel; +import com.github.hronom.robocraft.assistant.app.views.AssistantMainView; +import com.github.hronom.robocraft.assistant.app.views.ShootView; +import com.github.hronom.robocraft.assistant.core.Shooter; +import com.tulskiy.keymaster.common.HotKey; +import com.tulskiy.keymaster.common.HotKeyListener; +import com.tulskiy.keymaster.common.Provider; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.awt.*; +import java.awt.event.KeyEvent; +import java.io.File; +import java.util.concurrent.TimeUnit; + +import javax.swing.*; + +public class RobocraftAssistantApp { + private static final Logger logger = LogManager.getLogger(); + + public static void main(String[] args) throws InterruptedException, AWTException { + logger.info(RobocraftAssistantApp.class.getSimpleName()); + printSystemInfo(); + + ShooterModel shooterModel = new ShooterModel(); + + ShootView shootView = new ShootView(); + new ShootController(shooterModel, shootView); + new AssistantMainView(shootView); + } + + /*private static final Logger logger = LogManager.getLogger(); + + public static void main(String[] args) { + logger.info(ScrapeDatRoomsViewApp.class.getSimpleName()); + printSystemInfo(); + + ScrapeView scrapeView = new ScrapeView(); + new ScrapeButtonController(scrapeView); + new WebsiteUrlTypingController(scrapeView); + new GrabberSelectionController(scrapeView); + new ScrapeMainView(scrapeView); + + // testMotel6(); + // testRedRoof(); + // testRedLion(); + }*/ + + private static void printSystemInfo() { + logger.info("Java version: " + System.getProperty("java.version")); + logger.info("Java vendor: " + System.getProperty("java.vendor")); + logger.info("Java vendor url: " + System.getProperty("java.vendor.url")); + logger.info("Java home: " + System.getProperty("java.home")); + logger.info("Java vm specification version: " + + System.getProperty("java.vm.specification.version")); + logger.info( + "Java vm specification vendor: " + System.getProperty("java.vm.specification.vendor")); + logger.info( + "Java vm specification name: " + System.getProperty("java.vm.specification.name")); + logger.info("Java vm version: " + System.getProperty("java.vm.version")); + logger.info("Java vm vendor: " + System.getProperty("java.vm.vendor")); + logger.info("Java vm name: " + System.getProperty("java.vm.name")); + logger.info( + "Java specification version: " + System.getProperty("java.specification.version")); + logger + .info("Java specification vendor: " + System.getProperty("java.specification.vendor")); + logger.info("Java specification name: " + System.getProperty("java.specification.name")); + logger.info("Java class.version: " + System.getProperty("java.class.version")); + logger.info("Java class.path: " + System.getProperty("java.class.path")); + logger.info("Java library.path: " + System.getProperty("java.library.path")); + logger.info("Java io.tmpdir: " + System.getProperty("java.io.tmpdir")); + logger.info("Java compiler: " + System.getProperty("java.compiler")); + logger.info("Java ext.dirs: " + System.getProperty("java.ext.dirs")); + logger.info("OS name: " + System.getProperty("os.name")); + logger.info("OS arch: " + System.getProperty("os.arch")); + logger.info("OS version: " + System.getProperty("os.version")); + + // Total number of processors or cores available to the JVM. + logger.info("Available processors (cores): " + Runtime.getRuntime().availableProcessors()); + // Total amount of free memory available to the JVM. + logger.info("Free memory (bytes): " + Runtime.getRuntime().freeMemory()); + // This will return Long.MAX_VALUE if there is no preset limit. + long maxMemory = Runtime.getRuntime().maxMemory(); + // Maximum amount of memory the JVM will attempt to use. + logger.info( + "Maximum memory (bytes): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory)); + // Total memory currently in use by the JVM. + logger.info("Total memory (bytes): " + Runtime.getRuntime().totalMemory()); + // Get a list of all filesystem roots on this system. + File[] roots = File.listRoots(); + // For each filesystem root, print some info. + for (File root : roots) { + logger.info("File system root: " + root.getAbsolutePath()); + logger.info("Total space (bytes): " + root.getTotalSpace()); + logger.info("Free space (bytes): " + root.getFreeSpace()); + logger.info("Usable space (bytes): " + root.getUsableSpace()); + } + } + + /*private static void testMotel6() { + final Path resultsDir = Paths.get("motel6"); + final Path resultsPhotosDir = resultsDir.resolve("photos"); + + try { + PathsUtils.deletePathIfExists(resultsDir); + PathsUtils.createDirectoryIfNotExists(resultsDir); + PathsUtils.createDirectoryIfNotExists(resultsPhotosDir); + } catch (IOException e) { + logger.fatal(e); + } + + JxBrowserGrabber jxBrowserGrabber = new JxBrowserGrabber(); + String html = jxBrowserGrabber.grabContent( + "https://www.motel6.com/en/motels.nv.las-vegas.8612.html#?propertyId=8612&numGuests=1&checkinDate=2015-11-26&numNights=1&corporatePlusNumber=CP555996&travelAgentNumber=7724054"); + Motel6HtmlParser dataProvider = new Motel6HtmlParser(); + ArrayList roomInfos = dataProvider.parse(html, new RoomPhotoDownloader() { + @Override + public Path download(String url) { + try { + return NetworkUtils.downloadImage(url, resultsPhotosDir).toAbsolutePath(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + }); + + save(roomInfos, resultsDir); + } + + private static void testRedRoof() { + final Path resultsDir = Paths.get("redroof"); + final Path resultsPhotosDir = resultsDir.resolve("photos"); + + try { + PathsUtils.deletePathIfExists(resultsDir); + PathsUtils.createDirectoryIfNotExists(resultsDir); + PathsUtils.createDirectoryIfNotExists(resultsPhotosDir); + } catch (IOException e) { + logger.fatal(e); + } + + JxBrowserGrabber jxBrowserGrabber = new JxBrowserGrabber(); + String html = jxBrowserGrabber.grabContent( + "https://www.redroof.com/search/index.cfm?children=0&adults=1&SearchTerm=RRI570&checkin=11/30/15&checkout=12/31/15&rooms=1"); + RedRoofHtmlParser parser = new RedRoofHtmlParser(); + ArrayList roomInfos = parser.parse(html, new RoomPhotoDownloader() { + @Override + public Path download(String url) { + try { + return NetworkUtils.downloadImage(url, resultsPhotosDir); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + }); + + save(roomInfos, resultsDir); + } + + private static void testRedLion() { + final Path resultsDir = Paths.get("redlion"); + final Path resultsPhotosDir = resultsDir.resolve("photos"); + + try { + PathsUtils.deletePathIfExists(resultsDir); + PathsUtils.createDirectoryIfNotExists(resultsDir); + PathsUtils.createDirectoryIfNotExists(resultsPhotosDir); + } catch (IOException e) { + logger.fatal(e); + } + + JxBrowserGrabber jxBrowserGrabber = new JxBrowserGrabber(); + String html = jxBrowserGrabber.grabContent( + "https://reservations.redlion.com/ibe/index.aspx?dt1=5367&hgID=280&hotelID=2072&langID=1&checkin=11%2F22%2F2015&checkout=11%2F23%2F2015&adults=1&children=0&destination=Settle%20Inn%20%26%20Suites%20Harlan#ws-rsftr-0"); + RedLionHtmlParser parser = new RedLionHtmlParser(); + ArrayList roomInfos = parser.parse(html, new RoomPhotoDownloader() { + @Override + public Path download(String url) { + try { + return NetworkUtils.downloadImage(url, resultsPhotosDir).toAbsolutePath(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + }); + + save(roomInfos, resultsDir); + } + + private static void save(ArrayList roomInfos, Path resultsPath) { + CsvMapper mapper = new CsvMapper(); + mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); + + CsvSchema schema = mapper.schemaFor(RoomInfo.class).withColumnSeparator(',').withHeader(); + + try (BufferedWriter bw = Files.newBufferedWriter(resultsPath.resolve("results.csv"))) { + mapper.writer(schema).writeValues(bw).writeAll(roomInfos); + } catch (IOException e) { + e.printStackTrace(); + } + }*/ +} diff --git a/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/controllers/ShootController.java b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/controllers/ShootController.java new file mode 100644 index 0000000..009b6a1 --- /dev/null +++ b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/controllers/ShootController.java @@ -0,0 +1,22 @@ +package com.github.hronom.robocraft.assistant.app.controllers; + +import com.github.hronom.robocraft.assistant.app.models.ShooterModel; +import com.github.hronom.robocraft.assistant.app.views.ShootView; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ShootController { + public ShootController(ShooterModel shooterModel, ShootView shootViewArg) { + shootViewArg.addApplySettingsButtonActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + shooterModel.set( + shootViewArg.key().toUpperCase().charAt(0), + Integer.valueOf(shootViewArg.shootDelay()), + Integer.valueOf(shootViewArg.shootCount()) + ); + } + }); + } +} \ No newline at end of file diff --git a/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/models/ShooterModel.java b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/models/ShooterModel.java new file mode 100644 index 0000000..99000d6 --- /dev/null +++ b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/models/ShooterModel.java @@ -0,0 +1,29 @@ +package com.github.hronom.robocraft.assistant.app.models; + +import com.github.hronom.robocraft.assistant.core.Shooter; +import com.tulskiy.keymaster.common.HotKey; +import com.tulskiy.keymaster.common.HotKeyListener; +import com.tulskiy.keymaster.common.Provider; + +import java.awt.*; + +import javax.swing.*; + +public class ShooterModel { + private final Provider provider = Provider.getCurrentProvider(true); + private Shooter shooter; + + public ShooterModel() throws AWTException, InterruptedException { + shooter = new Shooter(); + } + + public void set(Character keyChar, int shootDelay, int shootCount) { + provider.reset(); + provider.register(KeyStroke.getKeyStroke(String.valueOf(keyChar)), new HotKeyListener() { + public void onHotKey(HotKey hotKey) { + shooter.toggle(); + } + }); + shooter.resetAndStart(shootDelay, shootCount); + } +} diff --git a/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/AssistantMainView.java b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/AssistantMainView.java new file mode 100755 index 0000000..5718e2b --- /dev/null +++ b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/AssistantMainView.java @@ -0,0 +1,46 @@ +package com.github.hronom.robocraft.assistant.app.views; + +import java.awt.*; +import java.net.URL; +import java.util.ArrayList; + +import javax.swing.*; + +public class AssistantMainView { + public AssistantMainView(ShootView shootView) { + JPanel mainPanel = new JPanel(); + mainPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); + + GridBagLayout layout = new GridBagLayout(); + mainPanel.setLayout(layout); + + GridBagConstraints constraint = new GridBagConstraints(); + constraint.insets = new Insets(3, 3, 3, 3); + constraint.weightx = 1; + constraint.weighty = 1; + constraint.gridx = 0; + constraint.gridy = 0; + constraint.gridwidth = 1; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + mainPanel.add(shootView, constraint); + + ArrayList images = new ArrayList<>(); + images.add(getImage("1461511403_robot_64.png")); + + JFrame frame = new JFrame("Robocraft assistant"); + frame.setIconImages(images); + frame.setContentPane(mainPanel); + frame.setPreferredSize(new Dimension(500, 150)); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private Image getImage(String fileName) { + URL url = this.getClass().getResource(fileName); + ImageIcon imageIcon = new ImageIcon(url); + return imageIcon.getImage(); + } +} diff --git a/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/ShootView.java b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/ShootView.java new file mode 100755 index 0000000..8d4ce79 --- /dev/null +++ b/robocraft-assistant-app/src/main/java/com/github/hronom/robocraft/assistant/app/views/ShootView.java @@ -0,0 +1,146 @@ +package com.github.hronom.robocraft.assistant.app.views; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.awt.*; +import java.awt.event.ActionListener; + +import javax.swing.*; +import javax.swing.event.DocumentListener; + +public class ShootView extends JPanel { + private static final Logger logger = LogManager.getLogger(); + + private final JLabel shootDelayLabel; + private final JTextField shootDelayTextField; + + private final JLabel shootCountLabel; + private final JTextField shootCountTextField; + + private final JLabel keyLabel; + private final JTextField keyTextField; + + private final JButton applySettingsButton; + + public ShootView() { + this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); + + GridBagLayout layout = new GridBagLayout(); + this.setLayout(layout); + + GridBagConstraints constraint = new GridBagConstraints(); + constraint.insets = new Insets(3, 3, 3, 3); + constraint.weightx = 1; + constraint.weighty = 0; + constraint.gridwidth = 1; + constraint.anchor = GridBagConstraints.CENTER; + + { + shootDelayLabel = new JLabel("Shoot delay:"); + + constraint.weightx = 0; + constraint.weighty = 0; + constraint.gridx = 0; + constraint.gridy = 0; + constraint.gridwidth = 1; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + this.add(shootDelayLabel, constraint); + } + + { + shootDelayTextField = new JTextField("1000"); + + constraint.weightx = 1; + constraint.weighty = 0; + constraint.gridx = 1; + constraint.gridy = 0; + constraint.gridwidth = 1; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + this.add(shootDelayTextField, constraint); + } + + { + shootCountLabel = new JLabel("Shoot count:"); + + constraint.weightx = 0; + constraint.weighty = 0; + constraint.gridx = 0; + constraint.gridy = 1; + constraint.gridwidth = 1; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + this.add(shootCountLabel, constraint); + } + + { + shootCountTextField = new JTextField("5"); + + constraint.weightx = 1; + constraint.weighty = 0; + constraint.gridx = 1; + constraint.gridy = 1; + constraint.gridwidth = 1; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + this.add(shootCountTextField, constraint); + } + + { + keyLabel = new JLabel("Key:"); + + constraint.weightx = 0; + constraint.weighty = 0; + constraint.gridx = 0; + constraint.gridy = 2; + constraint.gridwidth = 1; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + this.add(keyLabel, constraint); + } + + { + keyTextField = new JTextField("R"); + + constraint.weightx = 1; + constraint.weighty = 0; + constraint.gridx = 1; + constraint.gridy = 2; + constraint.gridwidth = 1; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + this.add(keyTextField, constraint); + } + + { + applySettingsButton = new JButton("Apply settings"); + + constraint.weightx = 1; + constraint.weighty = 0; + constraint.gridx = 0; + constraint.gridy = 3; + constraint.gridwidth = 2; + constraint.gridheight = 1; + constraint.fill = GridBagConstraints.BOTH; + this.add(applySettingsButton, constraint); + } + } + + public String shootDelay() { + return shootDelayTextField.getText(); + } + + public String shootCount() { + return shootCountTextField.getText(); + } + + public String key() { + return keyTextField.getText(); + } + + public void addApplySettingsButtonActionListener(ActionListener actionListener) { + applySettingsButton.addActionListener(actionListener); + } +} diff --git a/robocraft-assistant-app/src/main/resources/com/github/hronom/robocraft/assistant/app/views/1461511403_robot_64.png b/robocraft-assistant-app/src/main/resources/com/github/hronom/robocraft/assistant/app/views/1461511403_robot_64.png new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xml new file mode 100755 index 0000000..543f43e --- /dev/null +++ b/robocraft-assistant-app/src/main/resources/log4j2.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/robocraft-assistant-core/src/main/java/com/github/hronom/robocraft/assistant/core/Shooter.java b/robocraft-assistant-core/src/main/java/com/github/hronom/robocraft/assistant/core/Shooter.java index d70627b..a5ee618 100755 --- a/robocraft-assistant-core/src/main/java/com/github/hronom/robocraft/assistant/core/Shooter.java +++ b/robocraft-assistant-core/src/main/java/com/github/hronom/robocraft/assistant/core/Shooter.java @@ -9,59 +9,49 @@ import javax.swing.*; public class Shooter { + private final int mask = InputEvent.BUTTON1_DOWN_MASK; + private final AtomicBoolean enabled = new AtomicBoolean(false); + private int shootCount; + private final Robot robot; + private final Timer timer; public Shooter() throws AWTException { robot = new Robot(); - int delay = 1000; //milliseconds - ActionListener taskPerformer = new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (enabled.get()) { - int mask = InputEvent.BUTTON1_DOWN_MASK; - - robot.mousePress(mask); - robot.delay(10); - robot.mouseRelease(mask); - - robot.delay(100); - - robot.mousePress(mask); - robot.delay(10); - robot.mouseRelease(mask); - - robot.delay(100); - - robot.mousePress(mask); - robot.delay(10); - robot.mouseRelease(mask); - - robot.delay(100); - - robot.mousePress(mask); - robot.delay(10); - robot.mouseRelease(mask); + ActionListener taskPerformer = createTaskPerformer(); + timer = new Timer(-1, taskPerformer); + timer.setRepeats(true); + } - robot.delay(100); + public void resetAndStart(int shootDelayArg, int shootCountArg) { + shootCount = shootCountArg; + timer.stop(); + timer.setDelay(shootDelayArg); + timer.start(); + } - robot.mousePress(mask); - robot.delay(10); - robot.mouseRelease(mask); + public void toggle() { + enabled.set(!enabled.get()); + } - /*robot.delay(100); + private ActionListener createTaskPerformer() { + return new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (enabled.get()) { + for (int i = 0; i < shootCount; i++) { + robot.mousePress(mask); + robot.delay(10); + robot.mouseRelease(mask); - robot.mousePress(mask); - robot.delay(10); - robot.mouseRelease(mask);*/ + if (i + 1 != shootCount) { + robot.delay(100); + } + } - //System.out.println("Shoot!!!"); + System.out.println("Shoot!!!"); } } }; - new Timer(delay, taskPerformer).start(); - } - - public void toggle() { - enabled.set(!enabled.get()); } }