Changeset 104 for java-automator/src/nl
- Timestamp:
- Apr 6, 2010, 8:47:34 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java-automator/src/nl/rickvanderzwet/farmville/ScreenRecognition.java
r103 r104 11 11 import java.awt.geom.Point2D; 12 12 import java.awt.image.BufferedImage; 13 import java.awt.image.Raster; 13 14 import java.awt.image.RasterFormatException; 14 15 import java.io.IOException; … … 21 22 static Point mouse; 22 23 static BufferedImage bi; 24 static Robot bot; 25 26 static boolean freezeImage = false; 27 28 private static void pressMouse() throws InterruptedException { 29 bot.mousePress(InputEvent.BUTTON1_MASK); 30 bot.mouseRelease(InputEvent.BUTTON1_MASK); 31 32 } 33 23 34 public ScreenRecognition() { 24 35 setTitle("Image demo Example"); … … 49 60 public void actionPerformed(ActionEvent event) { 50 61 Component c = (Component)event.getSource(); 51 System.out.println(c.getName()); 52 c.getToolkit().beep(); 62 if (c.getName() == "redButton") { 63 c.getToolkit().beep(); 64 try { 65 Thread.sleep(3000); 66 } catch (InterruptedException e) { 67 // TODO Auto-generated catch block 68 e.printStackTrace(); 69 } 70 freezeImage = !freezeImage; 71 } 53 72 } 54 73 … … 58 77 59 78 g.drawRect(18, 48, mouseSurround * 2 + 4, mouseSurround * 2 + 4); 79 g.setColor(pixel); 80 g.fillRect(300,100,20,20); 60 81 g.drawImage(bi,20, 50, this); 61 82 } … … 63 84 public static void main(String[] args) throws AWTException, InterruptedException { 64 85 //bot.mouseMove(100, 100); 65 Robotbot = new Robot();86 bot = new Robot(); 66 87 ScreenRecognition foo = new ScreenRecognition(); 67 88 … … 71 92 pixel = bot.getPixelColor(mouse.x, mouse.y); 72 93 try { 94 if (!freezeImage) { 73 95 bi=bot.createScreenCapture(new Rectangle(mouse.x + mouseSurround, 74 96 mouse.y + mouseSurround)); … … 76 98 mouse.y - mouseSurround, 77 99 mouseSurround * 2, mouseSurround * 2); 100 101 /* See is enabled */ 102 Color target = new Color(255, 170, 0); 103 int pixelTreshold = 10; 104 105 search: for (int x = 0; x < bi.getWidth(); x++) { 106 for (int y = 0; y < bi.getHeight(); y++){ 107 if (bi.getRGB(x, y) == target.getRGB()) { 108 pixelTreshold--; 109 if (pixelTreshold == 0) { 110 break search; 111 } 112 } 113 } 114 } 115 if (pixelTreshold == 0) { 116 pressMouse(); 117 System.out.println("Button Click"); 118 } 119 120 } 78 121 foo.repaint(); 79 122 } catch (IllegalArgumentException e) {
Note:
See TracChangeset
for help on using the changeset viewer.