绿/搜索【编程进阶路】 联系小编
robot.delay(3000);
//鼠标移动到起始点位
robot.mouseMove(beginPx, beginPy);
robot.delay(100);
//鼠标点击左键
robot.mousePress(InputEvent.BUTTON1_MASK);
//鼠标画圈
circle(robot);
//释放鼠标左键
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
//画圆圈
public static void circle(Robot robot) {
int px=beginPx;
int py=beginPy;
while (true){
if (flag == LEFT_RIGHT_DOWN) {//上半圆的运动轨迹方程
px += 1;
//y = b + (int) Math.sqrt(r^2 - (x - a)^2);
if (px <= centerPx+radio) {
py = centerPy - (int) Math.sqrt( Math.pow(radio, 2) - Math.pow( (px - centerPx),2 ) );
}else {
px = centerPx + radio;
flag = RIGHT_LEFT_UP;
}
}else if (flag == RIGHT_LEFT_UP) {//下半圆的运动轨迹方程
px -= 1;
if (px >= centerPx - radio) {
py = centerPy + (int) Math.sqrt( Math.pow(radio, 2) - Math.pow( (px - centerPx),2 ) );
}else{
px = centerPx - radio;
flag = LEFT_RIGHT_DOWN;
}
}
robot.mouseMove(px, py);
robot.delay(20);
if(pxbeginPx&&pybeginPy){
break;
}
}
}
}
优化后代码,方便画多个圆
package com.tarzan.reptile.demo;
import java.awt.*;
import java.awt.event.InputEvent;
public class RobotPaint {
//上半圆
static int RIGHT_LEFT_UP = 1;
//下半圆
static int LEFT_RIGHT_DOWN = -1;
//标识
static int flag = LEFT_RIGHT_DOWN;
//java robot对象
static Robot robot;
static {
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws AWTException {
//运行后等待3秒,切换到画图界面
robot.delay(3000);
//鼠标画圈
circle(robot, 360, 540, 200);
//鼠标画圈
circle(robot, 460, 540, 200);
}
//画圆圈
public static void circle(Robot robot, int centerPx, int centerPy, int radio) {
int px = centerPx;
int py = centerPy - radio;
while (true) {
if (flag == LEFT_RIGHT_DOWN) {//上半圆的运动轨迹方程
px += 1;
//y = b + (int) Math.sqrt(r^2 - (x - a)^2);
if (px < centerPx + radio) {
py = centerPy - (int) Math.sqrt(Math.pow(radio, 2) - Math.pow((px - centerPx), 2));
} else {
px = centerPx + radio;
flag = RIGHT_LEFT_UP;
}
} else if (flag == RIGHT_LEFT_UP) {//下半圆的运动轨迹方程
px -= 1;
if (px > centerPx - radio) {
py = centerPy + (int) Math.sqrt(Math.pow(radio, 2) - Math.pow((px - centerPx), 2));
} else {
px = centerPx - radio;
flag = LEFT_RIGHT_DOWN;
总结
蚂蚁面试比较重视基础,所以Java那些基本功一定要扎实。蚂蚁的工作环境还是挺赞的,因为我面的是稳定性保障部门,还有许多单独的小组,什么三年1班,很有青春的感觉。面试官基本水平都比较高,基本都P7以上,除了基础还问了不少架构设计方面的问题,收获还是挺大的。
经历这次面试我还通过一些渠道发现了需要大厂真实面试主要有:蚂蚁金服、拼多多、阿里云、百度、唯品会、携程、丰巢科技、乐信、软通动力、OPPO、银盛支付、中国平安等初,中级,高级Java面试题集合,附带超详细答案,希望能帮助到大家。
。面试官基本水平都比较高,基本都P7以上,除了基础还问了不少架构设计方面的问题,收获还是挺大的。
经历这次面试我还通过一些渠道发现了需要大厂真实面试主要有:蚂蚁金服、拼多多、阿里云、百度、唯品会、携程、丰巢科技、乐信、软通动力、OPPO、银盛支付、中国平安等初,中级,高级Java面试题集合,附带超详细答案,希望能帮助到大家。
[外链图片转存中…(img-m5LwzpAz-1722056118985)]