forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotLesson.java
More file actions
62 lines (55 loc) · 2.09 KB
/
RobotLesson.java
File metadata and controls
62 lines (55 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package debugging;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
/**
* Created by husiv on 10/11/16.
*/
public class RobotLesson {
static JFrame jFrame = getFrame();
public static void main(String[] args) throws AWTException {
JPanel jPanel = new JPanel();
jFrame.add(jPanel);
JButton jButton = new JButton("add");
jPanel.add(jButton);
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jFrame.setTitle(jFrame.getTitle() + "1");
}
});
JButton jButton2 = new JButton("click add");
jPanel.add(jButton2);
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = graphicsEnvironment.getDefaultScreenDevice();
Robot robot = null;
try {
robot = new Robot(device);
} catch (AWTException e1) {
e1.printStackTrace();
}
robot.delay(1000);
robot.mouseMove(750 + jButton.getX() + 20, 250 + jButton.getY() + 30);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
// Rectangle rectangle = new Rectangle(0,0, 1000, 1000);
// BufferedImage image = robot.createScreenCapture(rectangle);
}
});
}
private static JFrame getFrame() {
JFrame jFrame = new JFrame();
jFrame.setBounds(750, 250, 500, 500);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setVisible(true);
return jFrame;
}
}