ジョシュ:
私は、マウスカーソルを移動して円を作成しようとしています。私は私が必要とする完璧な結果を得ることができるが、私は1つのループ内でこのことを達成したいと思います。ここに私のコードは次のとおりです。
try {
Robot robot = new Robot();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int centerX = screenSize.width / 2;
int centerY = screenSize.height / 2;
for(int lx = 0; lx < screenSize.width; lx++) {
for(int ly = 0; ly < screenSize.height / 2; ly++) {
if(Math.round(Math.sqrt(Math.pow(lx - centerX, 2) + Math.pow(ly - centerY, 2))) == centerY) {
Thread.sleep(3);
robot.mouseMove(lx, ly);
}
}
}
for(int lx = screenSize.width; lx > 0 ; lx--) {
for(int ly = screenSize.height / 2; ly < screenSize.height; ly++) {
if(Math.round(Math.sqrt(Math.pow(lx - centerX, 2) + Math.pow(ly - centerY, 2))) == centerY) {
Thread.sleep(3);
robot.mouseMove(lx, ly);
}
}
}
}
catch (AWTException e) {}
catch (InterruptedException e) {}
サム:
try {
Robot robot = new Robot();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int centerX = screenSize.width / 2;
int centerY = screenSize.height / 2;
int lx = 0;
for(int i = 0; i < screenSize.width * 2; i++) {
for(int ly = 0; ly < screenSize.height; ly++) {
lx = i > screenSize.width ? (screenSize.width * 2) - i : i;
if((i > screenSize.width && ly < centerY) || (i < screenSize.width && ly > centerY)) continue;
if(Math.round(Math.sqrt(Math.pow(lx - centerX, 2) + Math.pow(ly - centerY, 2))) == centerY) {
Thread.sleep(3);
robot.mouseMove(lx, ly);
}
}
}
}
catch (AWTException e) {}
catch (InterruptedException e) {}