private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 148, 120);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnStart = new JButton("Start");
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
while(chckbxNewCheckBox.isSelected()){
try {
Robot auto = new Robot();
auto.delay(2300);
auto.mouseMove(377, 182);
auto.mousePress(InputEvent.BUTTON3_DOWN_MASK);
auto.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
//
auto.delay(1000);
auto.mouseMove(466, 293);
auto.mousePress(InputEvent.BUTTON1_DOWN_MASK);
auto.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
//
auto.delay(1000);
auto.mouseMove(1061, 217);
auto.mousePress(InputEvent.BUTTON1_DOWN_MASK);
auto.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
//
auto.delay(8000);
auto.mouseMove(601, 493);
auto.mousePress(InputEvent.BUTTON1_DOWN_MASK);
auto.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
//
auto.delay(60000);
auto.mouseMove(387, 355);
auto.mousePress(InputEvent.BUTTON1_DOWN_MASK);
auto.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
//
auto.delay(8000);
auto.mouseMove(705, 652);
auto.mousePress(InputEvent.BUTTON1_DOWN_MASK);
auto.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
} catch (AWTException e) {
e.printStackTrace();
}
}
} });
btnStart.setBounds(10, 47, 89, 23);
frame.getContentPane().add(btnStart);
JCheckBox chckbxNewCheckBox = new JCheckBox("New check box");
chckbxNewCheckBox.setBounds(2, 7, 97, 23);
frame.getContentPane().add(chckbxNewCheckBox);
}
I'd like some advice on putting the commands for my robot in a loop and the loop only execute when a checkbox is selected. I've tried a few different ways of doing it but none seem to be working. I'm sure I'm missing something simple but I can't seem to find what it was. Although doing it for me would help, explaining it would be great too. I am using eclipse, and the windowbuilder to add items.