简体   繁体   English

如何在GWT中绘制画布

[英]How to draw in canvas in GWT

I have this simple jQuery code for drawing a triangle in a 40 by 40 canvas element: 我有这个简单的jQuery代码,可以在40 x 40的画布元素中绘制三角形:

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? 现在如何在GWT中做同样的事情? There is a tutorial at http://code.google.com/p/google-web-toolkit-incubator/wiki/GWTCanvas , but the page itself says that that is deprecated and suggests using http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/canvas/client/Canvas.html . http://code.google.com/p/google-web-toolkit-incubator/wiki/GWTCanvas上有一个教程,但该页面本身说已弃用,建议使用http:// google-web-toolkit .googlecode.com / svn / javadoc / latest / com / google / gwt / canvas / client / Canvas.html However the latter has no documentation on drawing. 但是,后者没有有关图纸的文档。 Can anyone tell me how to do it in GWT? 谁能告诉我如何在GWT中做到这一点?

With the canvas you can get the Context2d object, which has the same methods as your context1 variable. 使用画布,您可以获得Context2d对象,该对象具有与context1变量相同的方法。

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.com/ http://gwtcanvasdemo.appspot.com/

Before that download jwt-incubator http://www.java2s.com/Code/JarDownload/gwt-incubator/gwt-incubator.jar.zip and add inherited module in .gwt.xml file.Then add this jar to library. 在此之前,下载jwt-incubator http://www.java2s.com/Code/JarDownload/gwt-incubator/gwt-incubator.jar.zip并将继承的模块添加到.gwt.xml文件中,然后将此jar添加到库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM