私はJFrameであるプログラムを持っていますが、「開始」アクションを使用すると切り替えることができず、代わりに実行したままになり、強制的に閉じる必要があります:(理由を教えてください.私はコーディングが初めてで、ここで私のコードは私の間違いを見つけられません:
public class ClickBotSetUp extends JFrame {
static ClickBotSetUp frame;
static Robot robot;
public static void ClickBot() throws AWTException{
final Robot robot = new Robot();
robot.delay(2000);
while(true)
{
{
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(least);
}
}
}
public static void main(String[] args) throws IOException, AWTException {
frame = new ClickBotSetUp("setup speed");
frame.setVisible(true);
frame.setBackground(Color.WHITE);
robot = new Robot();
}
//settings
static int least = 100;
JTextField count;
JButton start;
static int bot = 0;
public ClickBotSetUp(String title) throws HeadlessException
{
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setSize(180, 145);
Container cont = getContentPane();
cont.setLayout(new BorderLayout());
((JComponent) cont).setBorder(BorderFactory.createEmptyBorder(15, 15,
15, 15));
//desing
JLabel instructions = new JLabel("low nubers can crash");
cont.add(instructions, BorderLayout.SOUTH);
//buttons
start = new JButton("start");
start.setAction(starting);
cont.add(start, BorderLayout.WEST);
//score
JPanel scores = new JPanel();
scores.setLayout(new BorderLayout());
cont.add(scores, BorderLayout.CENTER);
JPanel times = new JPanel();
times.setLayout(new BorderLayout());
scores.add(times, BorderLayout.WEST);
//times
count = new JTextField("100");
count.setEditable(false);
times.add(count, BorderLayout.CENTER);
JButton add10 = new JButton("+10");
add10.setAction(add_10);
times.add(add10, BorderLayout.NORTH);
JButton remove10 = new JButton("-10");
remove10.setAction(remove_10);
times.add(remove10, BorderLayout.SOUTH);
}
private AbstractAction starting = new AbstractAction("start") {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.setVisible(false);
try {
ClickBot();
} catch (AWTException e) {
e.printStackTrace();
}
}
};
private AbstractAction add_10 = new AbstractAction("+10") {
@Override
public void actionPerformed(ActionEvent arg0) {
least = least + 10;
count.setText("" +least+ "");
}
};
private AbstractAction remove_10 = new AbstractAction("-10") {
@Override
public void actionPerformed(ActionEvent arg0) {
if(least < 20){
}else{
least = least - 10;
count.setText("" +least+ "");
}
}
};
}