试图撰写节目,每3分钟播放一次节目(以阻止播放的屏幕),但我希望能够停下来并开始。 如下文所示,我建立了纽州和方法,但当你点击时,当你把步骤推到 lo中,而且实际上,它赢得了无限的 lo,看看你是否点了终点。
我已尝试过系统.exit(0)点击尾纽顿,带端纽顿的通行证错过了这种方法,而且你可以从该法典中看到,如果在坐期间有人试图看到我是否会注意到我!
任何帮助都将受到高度赞赏。
法典:
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test
{
boolean loop;
static boolean exit;
public static void main(String[] args) throws AWTException
{
System.out.println("before");
makeButtons();
System.out.println("after");
}
public static void makeButtons()
{
JFrame jfrMain = new JFrame ("Mouse Robot");
JPanel jplMain = new JPanel();
final JButton run = new JButton("Run");
final JButton end = new JButton("End");
run.setEnabled(true);
end.setEnabled(true);
run.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//run.setEnabled(false);
//end.setEnabled(true);
try {
run(true);
} catch (AWTException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
end.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
exit = true;
}
});
jplMain.setLayout(new FlowLayout());
jplMain.add(run);
jplMain.add(end);
jfrMain.getContentPane().add(jplMain, BorderLayout.CENTER);
jfrMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrMain.pack();
jfrMain.setVisible(true);
}
public static void run(boolean loop) throws AWTException
{
Robot r2d2 = new Robot();
while(loop)
{
System.out.println("1");
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
mousePoint.translate(0, 1);
r2d2.mouseMove(mousePoint.x, mousePoint.y);
r2d2.delay(60000);
//r2d2.delay(60000);
//r2d2.delay(60000);
System.out.println("2");
mousePoint = MouseInfo.getPointerInfo().getLocation();
mousePoint.translate(0, -1);
r2d2.mouseMove(mousePoint.x, mousePoint.y);
r2d2.delay(60000);
//r2d2.delay(60000);
//r2d2.delay(60000);
System.out.println("looping");
if (exit = true)
{
break;
}
}
}
}