最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to draw in canvas in GWT - Stack Overflow

programmeradmin4浏览0评论

I have this simple jQuery code for drawing a triangle in a 40 by 40 canvas element:

var context1 = $("#arrow_left").get(0).getContext('2d');
context1.beginPath();
context1.moveTo(25,0);
context1.lineTo(0,20);
context1.lineTo(25,40);
context1.lineTo(25,0);
context1.fill();
context1.closePath();

Now how do I do the same thing in GWT? There is a tutorial at , but the page itself says that that is deprecated and suggests using .html. However the latter has no documentation on drawing. Can anyone tell me how to do it in GWT?

I have this simple jQuery code for drawing a triangle in a 40 by 40 canvas element:

var context1 = $("#arrow_left").get(0).getContext('2d');
context1.beginPath();
context1.moveTo(25,0);
context1.lineTo(0,20);
context1.lineTo(25,40);
context1.lineTo(25,0);
context1.fill();
context1.closePath();

Now how do I do the same thing in GWT? There is a tutorial at http://code.google./p/google-web-toolkit-incubator/wiki/GWTCanvas, but the page itself says that that is deprecated and suggests using http://google-web-toolkit.googlecode./svn/javadoc/latest//google/gwt/canvas/client/Canvas.html. However the latter has no documentation on drawing. Can anyone tell me how to do it in GWT?

Share Improve this question asked Jan 17, 2013 at 12:58 NedStarkOfWinterfellNedStarkOfWinterfell 5,24328 gold badges112 silver badges204 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

With the canvas you can get the Context2d object, which has the same methods as your context1 variable.

Just call the same methods ;-)

Sample Code:

Canvas canvas = Canvas.createIfSupported();
Context2d context1 = canvas.getContext2d();
context1.beginPath();
context1.moveTo(25,0);
context1.lineTo(0,20);
context1.lineTo(25,40);
context1.lineTo(25,0);
context1.fill();
context1.closePath();

I think this following link will help you. It has source code also. http://gwtcanvasdemo.appspot./

Before that download jwt-incubator http://www.java2s./Code/JarDownload/gwt-incubator/gwt-incubator.jar.zip and add inherited module in .gwt.xml file.Then add this jar to library.

发布评论

评论列表(0)

  1. 暂无评论