Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在gwt中使用html5画布绘制一个圆圈?_Java_Html_Gwt_Canvas - Fatal编程技术网

Java 在gwt中使用html5画布绘制一个圆圈?

Java 在gwt中使用html5画布绘制一个圆圈?,java,html,gwt,canvas,Java,Html,Gwt,Canvas,我想在GWT中画一个圆圈,带有一些鼠标和拖放支持。在GWT中可以这样做吗?你能提供一个示例代码吗?是的,你能。伪代码如下所示- Canvas canvas = Canvas.createIfSupported(); Context2d context=canvas.getContext2d(); RootPanel.get(A_HOLDER_DIV_ID).add(canvas); 添加如下处理程序- 1) 鼠标向下移动处理程序以获取拖动的开始 canvas.addMouseDownHandl

我想在GWT中画一个圆圈,带有一些鼠标和拖放支持。在GWT中可以这样做吗?你能提供一个示例代码吗?

是的,你能。伪代码如下所示-

Canvas canvas = Canvas.createIfSupported();
Context2d context=canvas.getContext2d();
RootPanel.get(A_HOLDER_DIV_ID).add(canvas);
添加如下处理程序-

1) 鼠标向下移动处理程序以获取拖动的开始

canvas.addMouseDownHandler() - 
//catch the start of the circle drag, 
//clear the canvas
//Note the startx & starty
canvas.addMouseUpHandler() - 
//catch the end of the circle drag, 
//mark dragging as stopped
1) 鼠标向上移动处理程序,以获取拖动的开始和结束

canvas.addMouseDownHandler() - 
//catch the start of the circle drag, 
//clear the canvas
//Note the startx & starty
canvas.addMouseUpHandler() - 
//catch the end of the circle drag, 
//mark dragging as stopped
3) 鼠标移动处理程序以创建圆

canvas.addMouseMoveHandler() - 
//if drag started through event 1 then - 
//get x & y;
//calculate centre of circle and radius based on startx, starty and x & y above
//Clear the canvas
//And add the following code

context.setFillStyle(color);
context.beginPath();
context.arc(calculatedCenterx, calculatedCentery, radius, 0, Math.PI * 2.0, true);
context.closePath();
context.fill();
编辑-
看看这篇关于如何开始使用GWT HTML5画布的文章

是的,你可以。伪代码如下所示-

Canvas canvas = Canvas.createIfSupported();
Context2d context=canvas.getContext2d();
RootPanel.get(A_HOLDER_DIV_ID).add(canvas);
添加如下处理程序-

1) 鼠标向下移动处理程序以获取拖动的开始

canvas.addMouseDownHandler() - 
//catch the start of the circle drag, 
//clear the canvas
//Note the startx & starty
canvas.addMouseUpHandler() - 
//catch the end of the circle drag, 
//mark dragging as stopped
1) 鼠标向上移动处理程序,以获取拖动的开始和结束

canvas.addMouseDownHandler() - 
//catch the start of the circle drag, 
//clear the canvas
//Note the startx & starty
canvas.addMouseUpHandler() - 
//catch the end of the circle drag, 
//mark dragging as stopped
3) 鼠标移动处理程序以创建圆

canvas.addMouseMoveHandler() - 
//if drag started through event 1 then - 
//get x & y;
//calculate centre of circle and radius based on startx, starty and x & y above
//Clear the canvas
//And add the following code

context.setFillStyle(color);
context.beginPath();
context.arc(calculatedCenterx, calculatedCentery, radius, 0, Math.PI * 2.0, true);
context.closePath();
context.fill();
编辑-
请看一下如何开始使用GWT HTML5画布,这是一种方法。另一种方法是使用Lienzo这样的框架来抽象所有代码。您可以直接获得事件、动画和变换。Lienzo是一个Java图形工具包,使用GWT实现,目标是HTML5的画布。Lienzo是Apache2,所以它对所有人都是免费的

要使用Lienzo做一个圆,您可以执行以下操作:

Circle circle = new Circle(radius);
circle.setX(xCoord);
circle.setY(yCoord);
circle.setDraggable(true);
circle.addNodeMouseClickHandler(new NodeMouseClickHandler() {
    @Override
    public void onNodeMouseClick(NodeMouseClickEvent event) {
        ...
    }
});
你可以听更多的活动,但那是最常见的


祝你好运

这是一种方法。另一种方法是使用Lienzo这样的框架来抽象所有代码。您可以直接获得事件、动画和变换。Lienzo是一个Java图形工具包,使用GWT实现,目标是HTML5的画布。Lienzo是Apache2,所以它对所有人都是免费的

要使用Lienzo做一个圆,您可以执行以下操作:

Circle circle = new Circle(radius);
circle.setX(xCoord);
circle.setY(yCoord);
circle.setDraggable(true);
circle.addNodeMouseClickHandler(new NodeMouseClickHandler() {
    @Override
    public void onNodeMouseClick(NodeMouseClickEvent event) {
        ...
    }
});
你可以听更多的活动,但那是最常见的

祝你好运