package fr;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class MFrame extends JFrame {
/*****************
* 连点器
*
* ***/
JTextField jt = new JTextField("500,500");
JButton jb = new JButton("测试");
JButton jb1 = new JButton("运行");
boolean boo;//启动,停止
Robot b;
public MFrame() {
setSize(120, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
try {
b = new Robot();
} catch (AWTException e1) {
e1.printStackTrace();
}
jt.setBounds(10, 10, 100, 50);
add(jt);
jb.setBounds(10, 70, 100, 50);
add(jb);
jb1.setBounds(10, 70+60, 100, 50);
add(jb1);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = jt.getText();
String[] rt = str.split(",");
move(Integer.parseInt(rt[0]), Integer.parseInt(rt[1]));
}
});
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
public void run() {
String str = jt.getText();
String[] rt = str.split(",");
move(Integer.parseInt(rt[0]), Integer.parseInt(rt[1]));
long l = new Date().getTime() + 10*1000;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
while(new Date().getTime()<l) {
pressmouseas();
jb1.setText((l-new Date().getTime())/1000+"");
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
jb1.setText("运行");
}
}).start();
}
});
}
//模拟鼠标点击
public void pressmouseas() {
b.mousePress(InputEvent.BUTTON1_DOWN_MASK);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
b.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
//模拟鼠标移动
public void move(int x,int y) {
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
b.mouseMove(x,y);
}
}).start();;
}
public static void main(String[] args) {
new MFrame().setVisible(true);
}
}
java连点器
最新推荐文章于 2023-11-23 20:54:32 发布