循环完成后,所有按钮和文本字段都可以使用,但是当循环运行时,什么都不能点击。我尝试了很多不同的东西,查看了很多不同的网站,但没有什么能帮助我。我不知道出了什么问题!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class J extends JFrame implements ActionListener{
JButton start = new JButton("Start (F12)");
JButton stop = new JButton("Stop");
int i;
JLabel delay = new JLabel("Delay: ");
JTextField delayJTF = new JTextField(4);
int delayS = 0;
GridLayout bl = new GridLayout(10, 10);
public J()
{
super("Auto Clicker");
start.addActionListener(this);
stop.addActionListener(this);
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(bl);
add(delay, BorderLayout.NORTH);
add(delayJTF, BorderLayout.NORTH);
add(start);
add(stop);
setVisible(true);
}
boolean run = false;
public static void main(String[] args) {
J j = new J();
}
public void robott() {
try {
Robot robot = new Robot();
Thread.sleep(delayS);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
// robot.delay(delayS);
} catch(Exception exc) {
System.out.println(exc);
}
}
public void actionPerformed(ActionEvent e) {
String delaySt = delayJTF.getText();
delayS = Integer.parseInt(delaySt);
System.out.println(delayS);
while(i < 100) {
i++;
robott();
System.out.println(i);
}
}
}
any suggestions?