日期:2014-05-20 浏览次数:20949 次
package test;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.AWTException;
import java.awt.Button;
import java.awt.Label;
import java.awt.Robot;
import java.awt.TextField;
public class TT extends JFrame {
private int title = 0;
private int times;
final JFrame jf;
Button jb;
JPanel panel;
Label tx_lab;
final TextField tx;
static int command = 0;
public TT() {
jf = new JFrame(String.valueOf(title));
panel = new JPanel();
tx_lab = new Label("次数");
tx = new TextField();
jb = new Button("点我");
Label resolution_lab = new Label("坐标");
final TextField resolutionX = new TextField();
final TextField resolutionY = new TextField();
resolutionX.setText("1000");
resolutionY.setText("1000");
tx.setSize(50, 50);
tx.setText("5");
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Robot robot;
try {
robot = new Robot();
times = Integer.valueOf(tx.getText());
for (int i = 0; i < times; i++) {
robot.mouseMove(Integer.valueOf(resolutionY.getText()),
Integer.valueOf(resolutionY.getText()));
// robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(500);
// robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(500);
title++;
jf.setTitle(String.valueOf(title));
listener();
}
} catch (AWTException e1) {
e1.printStackTrace();
}
}
});
jf.add(panel);
panel.add(resolution_lab);
panel.add(resolutionX);
panel.add(resolutionY);
panel.add(tx_lab);
panel.add(tx);
panel.add(jb);
jf.pack();
jf.setSize(300, 300);
jf.setVisible(true);
}
public void listener() {
jb.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 27) {
System.exit(-1);
}
command = e.getKeyCode();
System.out.println(command);
}
});
}
public static void main(String[] args) throws Exception {
TT tt = new TT();
}
}
public class TT extends JFrame {
private int title = 0;
private int times;
final JFrame jf;
Button jb;
JPanel panel;
Label tx_lab;
final TextField tx;
static int command = 0;
public TT() {
jf = new JFrame(String.valueOf(title));
panel = new JPanel();
tx_lab = new Label("次数");
tx = new TextField();
jb = new Button("点我");
Label resolution_lab = new Label("坐标");
final TextField resolutionX = new TextField();
final TextField resolutionY = new TextField();
resolutionX.setText("1000");
resolutionY.setText("1000");
tx.setSize(50, 50);
tx.setText("5");
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
public void run() {
Robot robot;
try {
robot = new Robot();
times = Integer.valueOf(tx.getText());
for (int i = 0; i < times; i++) {