java画板设置下拉框_在Java中如何在画布上绘制框时显示拖动动画?

这是我的mouseDown和mouseUp代码:

public Canvas(int width, int height) {

element = getElement();

element.addEventListener("mousedown", event -> { // Retrieve Starting Position on MouseDown

Element boundingBoxResult = ElementFactory.createDiv();

element.appendChild(boundingBoxResult);

JsonObject evtData = event.getEventData();

double xBox = evtData.getNumber("event.x");

double yBox = evtData.getNumber("event.y");

boundingBoxResult.setAttribute("data-x", String.format("%f", xBox));

boundingBoxResult.setAttribute("data-y", String.format("%f", yBox));

BoundingBox newBox = new BoundingBox(0, xBox, yBox, 0.0, 0.0);

arrayBoxes.add(newBox);

isDrawing = true;

mouseIsDown=true;

}).addEventData("event.x").addEventData("event.y");

element.addEventListener("mouseup", event -> { // Draw Box on MouseUp

Element boundingBoxResult2 = ElementFactory.createDiv();

element.appendChild(boundingBoxResult2);

JsonObject evtData2 = event.getEventData();

endX = evtData2.getNumber("event.x");

endY = evtData2.getNumber("event.y");

boundingBoxResult2.setAttribute("end-x", String.format("%f", endX));

boundingBoxResult2.setAttribute("end-y", String.format("%f", endY));

double xcoordi = 0;

double ycoordi = 0;

double boxWidth = 0;

double boxHeight = 0;

for (int i = 0; i < arrayBoxes.size(); i++) {

arrayBoxes.get(i).setName(i + 1);

arrayBoxes.get(i).setWidth(endX, arrayBoxes.get(i).xcoordi);

arrayBoxes.get(i).setHeight(endY, arrayBoxes.get(i).ycoordi);

xcoordi = arrayBoxes.get(i).getXcoordi();

ycoordi = arrayBoxes.get(i).getYcoordi();

boxWidth = arrayBoxes.get(i).getWidth();

boxHeight = arrayBoxes.get(i).getHeight();

}

mouseIsDown=false;

context.beginPath();

context.setFillStyle("limegreen");

context.setLineWidth(2);

context.strokeRect(xcoordi, ycoordi, boxWidth, boxHeight);

context.fill();

System.out.println(arrayBoxes.toString());

}).addEventData("event.x").addEventData("event.y");

}

非常感谢您的帮助,谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值